MATLAB: How to use the ‘least square fit’

least square fit

i have a function:
f(t)=Asin(Bt^C+D)e^(-Et)+F
and starting point values:
A = -6, B = 1, C = 1, D = 0, E = 0, F = 0.
and xdata = 0:0.51:195*0.51
and ydata is a 1*196 vector
how can i use lsqcurvefit() to fit my data?

Best Answer

xdata = 0:0.51:195*0.51;
ydata = ...;
fun = @(x,xdata)x(1)*sin(x(2)*xdata.^x(3)+x(4)).*exp(-x(5)*xdata)+x(6);
x0 = [-6 ,1 ,1 ,0 ,0 ,0];
x = lsqcurvefit(fun,x0,xdata,ydata)