%%Example1 nonlinear data %x1=[0 1 2 3 4 5 6 7 8 9]; %y1=[3.8 3.7 4.0 3.9 4.3 4.2 4.2 4.4 4.5 4.9]; x1=-2:2; y1=[1 2 3 3 4]; plot(x1,y1,'-o')% Plot the data fun=@(x,x1)x(1)+x(2)*x1+x(3)*x1.^2; x0=[0.2 0.5 0.02]; % initial guess times = linspace(x1(1),x1(end)); %[x,resnorm,residual,exitflag,output,lambda,jacobian] = lsqcurvefit(fun,x0,x1,y1) [x] = lsqcurvefit(fun,x0,x1,y1) plot(x1,y1,'ko',times,fun(x,times),'b-','LineWidth',2)% Linear fit curve plot legend('Data','nonlinear fit') title(' Quadratic model curve fit') xlabel('x') ylabel('y') grid on