
format compact

x=-10:0.1:10;
N=length(x);

y = cos(x);
yp = y+ 0.5*(rand(1,N)-0.5);


fitting_func = inline('p(1).*cos(p(2).*x+p(3))','p','x');

options = optimset('Display','off','TolFun',1e-10);
param0 = [1.1 0.9 0.2]
param1=lsqcurvefit(fitting_func, param0, x, yp,[],[],options)

y0=fitting_func(param0,x);
y1=fitting_func(param1,x);

plot(x,yp,'o',x,y0,x,y1)

legend('data','guess','fit')

