MATLAB: Minimize the error between the measured y values when give a set of data:

MATLAB

I'm having trouble understanding this problem and assume that we'll trying to find the best fit curve:
I do have some coding done, but I'm not sure if I'm going in the right direction. I would like if this was explain clearly. I have also attached the given data that contains 2 matfiles x and y_noise. Thanks.
load 'prob3.mat'
c_1 = x;
c_2 = y_noise;
y = c_1.*cos(x) + c_2.*exp(-x)
This is my beginning code. But looks off from what is being asked.

Best Answer

Use an anonymous function to create your ‘y’ function, then use the norm function to create your cost function, then the fminsearch function to do the ‘minimize’ step. See the section on ‘Anonymous Functions’ in Function Basics for details.
If you want to write a fitting function for:
y = m*x + b
you would write it as:
yfun = @(b,x) b(1).*x + b(2);
That should give you a hint on how to go about this.
Related Question