MATLAB: How to carry out lease square fitting

lsqcurvefit

Hi, I am attempting to fit data that should fit the following function:
F =1i*x(1)+1i*(x(2)-x(1))./(1+(1i*2*pi*freq*x(3))).^(1-x(4))-1i*xdata
x(1:4) are the constants that needs to be optimizeed and omega (2*pi*freq) is the variable for the function. I have xdata and ydata for each freq value.
Following is the code I written but it gives Solver stopped prematurely.
freq = 100:100:1000; Rdata=[500 800 1000 2000 3500 5000 7500 10000 11000 12000]; Idata = [300 600 900 1500 2000 1800 1200 800 500 200]; plot(Rdata,Idata,'ro') F = @(x,xdata)1i*x(1)+1i*(x(2)-x(1))./(1+(1i*2*pi*freq*x(3))).^(1-x(4))-1i*xdata; x0 = [1 1 1 0]; [x,resnorm,~,exitflag,output] = lsqcurvefit(F,x0,Rdata,Idata); plot(Rdata,F(x,Rdata))
Could you please help me in solving this problem.

Best Answer

If the solver stopped prematurely, it means that it reached the limit of function evaluations or iterations before it minimised the function. Use the optimoptions function to increase the number of function evaluations, iterations, or whatever lsqcurvefit asks you to increase. This is not an error but a suggestion.
Related Question