Problem 44508. Curve fitting (non-linear functions) & function handles

In this problem you are provided some raw data. You need to find a way of summarising the data with just a few parameters, so that it can be reconstructed. You then need to provide a handle to your own (generic) custom function that will indeed reproduce the raw data when provided with the parameters that you determine.
Consider a non-linear scalar function y = mˣ + c. Suppose x is the vector [3 2 1 4]. The function would operate elementwise on x; for example, if m=2 and c=3 then y = [11 7 5 19]. You are provided with both the vector x and the vector y. Every number will be provided in some form of an integer data type. The scalar parameters m and c are both whole numbers (although they're not provided directly).
So here you should output two things:
  1. the handle to a generic function that implements the relevant non-linear function (i.e. of the form y = mˣ + c) taking two inputs, namely 1 a set of parameters and 2 the vector x, and outputting the corresponding vector y (in any data type); and
  2. a set of parameter values (m and c) wrapped into a single MATLAB variable (of any data type).
As the parameters will be used in your own function, the data type will be set by you.
So, for the above example, you could return a function handle @myFunc that you have defined, along with the variable param that has two fields such that param.base = 2 and param.translation = 3.
Or, if you have defined your function differently, then you could return the function handle @myFn along with a cell array variable prms that has four elements such that prms{1}='positive', prms{2}=uint8(3), prms{3} = 'positive' and prms{4} = uint8(2).
And so on.
Note 1: the parameter m can be assumed to have values between -30 and +30 (inclusive); the parameter c can be assumed to have values between -10000 and +10000 (inclusive); the elements in x are positive.
Note 2: if the code runs too slowly, then it will also fail the Test Suite.
Note 3: there might not be only one unique pair of the m & c parameter values that is correct — the individual values of m & c are not tested here, only the values of y that they predict are examined.

Solution Stats

14.71% Correct | 85.29% Incorrect
Last Solution submitted on Nov 14, 2020

Problem Comments

Solution Comments

Show comments

Problem Recent Solvers2

Suggested Problems

More from this Author32

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!