I am trying to fit some data using the following code:
xdata = [0.0600 0.1250 0.2540 0.4050 0.5450];ydata = [0.0800 0.1000 0.1200 0.1400 0.1600]; objfcn = @(x)(x(1)*x(2))./((x(2)*(1-xdata)./xdata)+(1-xdata)*(x(2)-1))-ydata; x0 = rand(2,1); opts = optimoptions(@lsqnonlin,'Algorithm','levenberg-marquardt','Display','iter'); [x,resnorm]=lsqnonlin(objfcn,x0,[],[],opts); M = x(1) B = x(2)
I am getting results but sometimes M value is coming negative which is not desirable. Also, the predicted ydata deviates largely from the original ydata values. If someone could be help to analyze the small code mentioned above and what is the wrong with results.
Thanks,
Best Answer