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:
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.
It might be nice to replace assert(isequal(y,y_correct)) by something along the lines of assert(max(abs(y-y_correct))<1e-9) to allow for roundoff errors.
Hello, Tim. Thank-you for your suggestion. Although it hadn't been mentioned, _all_ of the relevant numbers (x(i), y(i), m and c) are integers, so I didn't expect rounding would be a problem. [Certainly it wasn't in my reference code.] In any case, the secondary application I had in mind was lossless compression, so I am not keen to change the assertions in this particular problem (although I agree that often, elsewhere, it is indeed good to implement assertions as in your snippet). I will instead add a note to the Problem Statement. —David
Given an unsigned integer x, find the largest y by rearranging the bits in x
577 Solvers
3753 Solvers
105 Solvers
Find the index of the largest value in any vector X=[4,3,4,5,9,12,0,4.....5]
239 Solvers
524 Solvers