Error: lsqcurvefit stopped because it exceeded the function evaluation limit,

75 views (last 30 days)
I got the code below and was trying to run it but this error always occured: lsqcurvefit stopped because it exceeded the function evaluation limit,
It would be nice if someone please could help me. Thank you!
% Daten m1
omega_m1=[5.23598776, 4.48798951, 3.92699082, 3.4906585, 3.14159265, 2.991993, 2.85599332, 2.7925268, 2.7318197, 2.67369588, 2.61799388, 2.58567297, 2.56456543, 2.55414037, 2.54379972, 2.53354246, 2.52336759, 2.51327412, 2.4933275, 2.46399424, 2.41660973, 2.37101332, 2.32710567, 2.24399475, 2.0943951, 1.96349541, 1.7951958, 1.65346982];
amplitude_m1=[0.00375,0.0055,0.0075,0.011,0.0175,0.026,0.0356,0.041,0.0585,0.077,0.129,0.175,0.21,0.219,0.223,0.225,0.224,0.208,0.169,0.116,0.083,0.063,0.055,0.04,0.029,0.022,0.018,0.016];
phase_m1=[0.5];
%Plot Amplitude m1
plot(omega_m1, amplitude_m1, 'o', 'linewidth', 2);
xlabel('Frequenz \omega in 1/s');
ylabel('Amplitude A in m');
title('Resonanzkurve für m=1');
legend('Messdaten m=1');
%Fitting der Amplitude m=1
xdata=omega_m1;
ydata=amplitude_m1;
%options=optimoptions(@lsqcurvefit,'Algorithm','levenberg-marquardt', 'MaxFunctionEvaluations',2000000, 'MaxIterations', 200000, 'StepTolerance',1e-10);
x_0=[1,6]
fun=@(x,xdata) 0.9./((1-xdata.^2./x(1).^2).^2+xdata.^2./(x(2).^2.*x(1).^2)).^(0.5);
x=lsqcurvefit(fun,x_0,xdata,ydata);
times=linspace(xdata(1),xdata(end));
plot(xdata,ydata,'ko',times,fun(x,times),'r-','LineWidth',2)
xlabel('Frequenz \omega in 1/s');
ylabel('Amplitude A in m');
title('Resonanzkurve für m=1');
%Maximum der Amplitude
Max_m1=findpeaks(fun(x,times))
hold off;
%Plot der Phase
plot(omega_m1,phase_m1,'o','LineWidth',2);
xlabel('Frequenz \omega in 1/s');
ylabel('Phase \phi');
title('Relativphase zwischen Motor und Schiffchen für m=1');
legend('Messdaten m=1');
%Fitting der Phase
xdata=omega_m1;
ydata=phase_m1;
x_0=[2.5,6]
fun=@(x,xdata)mod((atanx(1).*xdata./x(2).*(x(1).^2-xdata.^2)),pi);
x=lsqcurvefit(fun,x_0,xdata,ydata);
times=linespace(xdata(1),xdata(end));
plot(xdata,ydata,'ko',times,fun(x,times),'r-','linewidth',2);
xlabel('Frequenz \omega in 1/s');
ylabel('Phase \phi');
title('Relativphase zwischen Motor und Schiffchen m=1');
label('Messdaten','Fittkurve');

Answers (1)

Alan Moses
Alan Moses on 4 Dec 2020
Hi,
You may refer to the answer to a similar question posted here. Refer the optimoptions documentation to look up the different options available for the solver.
On reproducing the code there seems to be few errors. On line 41, ‘atanx’ produces an error since it is unrecognized. You may refer atan function. Sine the function ‘fun’ on line 41 produces a vector output of the same size as that of ‘xdata’, the ‘ydata’ also must be of the same size as that produced by ‘fun’. You may refer to ones function to extend the size of the vector with the same values. The variable ‘phase_ml’ on line 4 needs to be extended in this case. In the last line, you may use the legend function instead of ‘label’.
You may refer the below lines of code with the changes:
phase_m1=0.5*ones(1,28); %Line 4
fun=@(x,xdata)mod((atan(1).*xdata./x(2).*(x(1).^2-xdata.^2)),pi); %Line 41
legend('Messdaten','Fittkurve'); %Line 48
Hope this helps!

Products


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!