Cody

Problem 44507. Curve fitting (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 linear function y = m x + c. Let's say x is a vector of uniformly spaced numbers, such as 1:100. The function operates on the data to produce, say, y = 2:2:200. You are provided with both the vector x and the vector y. The parameters m and c are scalars; in this example m is 2 and c is zero.

So here you should output two things:

  • the handle to a generic function that implements a linear function (i.e. of the form y = m x + c) taking two inputs, namely 1 a set of parameters and 2 the vector x, and outputting the corresponding vector y; and
  • 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.amplification = 2 and param.verticalShift = NaN.

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}='no', prms{2}=NaN, prms{3} = 'yes' and prms{4} = 2.

And so on.

Note: all of the relevant numbers ( m, c and the elements of x and y) are integers (i.e. whole numbers, not decimals or fractions), even though they have been implicitly specified as being of type double.

Solution Stats

75.0% Correct | 25.0% Incorrect
Last Solution submitted on Feb 27, 2019

Problem Comments