lsqnonlin evaluation limit problem

5 vues (au cours des 30 derniers jours)
Mustafa Duran
Mustafa Duran le 9 Août 2023
Commenté : Mustafa Duran le 10 Août 2023
I solved nonlinear overdetermined equation system in MATLAB. But there is an error about evaluation limit:
lsqnonlin stopped because it exceeded the function evaluation limit,
options.MaxFunctionEvaluations = 4.000000e+02.
How can i solve it?
MY CODE is:
clear all
clc
x1=0;
y1=0;
z1=4;
x2=0;
y2=0.6;
z2=4;
x3=0.519;
y3=0.3;
z3=4;
x4=0.173;
y4=0.3;
z4=4.3;
x5=0.173;
y5=0.3;
z5=3.7;
t21=-0.00137932379670;%s
t31=-0.00164153231470;%s
t41=-0.00100559463380;%s
t51=-0.00100817984660;%s
% t21=0.00165340883470;%s
% t31=0.00183950027910;%s
% t41=0.00018624479890;%s
% t41=0.00092230781380;%s
c=340.0;%m/s
D21=t21*c;%m
D31=t31*c;%m
D41=t41*c;%m
D51=t51*c;%m
k1=((x1)^2+(y1)^2+(z1)^2);
k2=((x2)^2+(y2)^2)+(z2)^2;
k3=((x3)^2+(y3)^2)+(z3)^2;
k4=((x4)^2+(y4)^2)+(z4)^2;
k5=((x5)^2+(y5)^2)+(z5)^2;
%A=D21^2+2*D21*D1==-2*x*(x2-x1)-2*y*(y2-y1)-2*z*(z2-z1)+k2-k1;
%B=D31^2+2*D31*D1==-2*x*(x3-x1)-2*y*(y3-y1)-2*z*(z3-z1)+k3-k1;
%C=D41^2+2*D41*D1==-2*x*(x4-x1)-2*y*(y4-y1)-2*z*(z4-z1)+k4-k1;
%E=D51^2+2*D51*D1==-2*x*(x5-x1)-2*y*(y5-y1)-2*z*(z5-z1)+k5-k1;
%D=D1^2==x^2+y^2-2*x*x1-2*y*y1-2*z*z1+k1;
f = @(x) [-2*x(1)*(x2-x1)-2*x(2)*(y2-y1)-2*x(3)*(z2-z1)+k2-k1-(D21^2+2*D21*x(4));
-2*x(1)*(x3-x1)-2*x(2)*(y3-y1)-2*x(3)*(z3-z1)+k3-k1-(D31^2+2*D31*x(4));
-2*x(1)*(x4-x1)-2*x(2)*(y4-y1)-2*x(3)*(z4-z1)+k4-k1-(D41^2+2*D41*x(4));
-2*x(1)*(x5-x1)-2*x(2)*(y5-y1)-2*x(3)*(z5-z1)+k5-k1-(D51^2+2*D51*x(4));
x(1)^2+x(2)^2-2*x(1)*x1-2*x(2)*y1-2*x(3)*z1+k1-(x(4)^2)]; % define f
for a=0:1:5
for b=0:1:5
for c=0:1:5
for d=0:1:5
x0 = [a;b;c;d]; % initial guess
[xs,fnorm2] = lsqnonlin(f,x0); % find solution xs
fnorm = sqrt(fnorm2);
if fnorm<0.1
break;
fnorm
end
end
end
end
end

Réponses (1)

Walter Roberson
Walter Roberson le 9 Août 2023
Initialize
opts = optimoptions('lsqnonlin', 'MaxFunctionEvaluations', 10000, 'MaxIterations', 10000);
LB = []; UB = []; A = []; B = []; Aeq = []; Beq = []; NONLCON = [];
Then change
[xs,fnorm2] = lsqnonlin(f,x0); % find solution xs
to
[xs,fnorm2] = lsqnonlin(f, x0, LB, UB, A, B, Aeq, Beq, NONLCON, opts); % find solution xs
  4 commentaires
Stephen23
Stephen23 le 9 Août 2023
Modifié(e) : Stephen23 le 9 Août 2023
"but this time MATLAB gives the error of.."
In addition to what Walter Roberson wrote, note that it is not an error message (error messages are always red and (usually) start with the text "Error..."), it is simply the default display text the the optimzation routines print to the command window, to inform you how the optimization went (Walter Roberson explained why this is required/useful information).
You can find other display options in the documentation:
Mustafa Duran
Mustafa Duran le 10 Août 2023
That clarified well to me and my code. Whatever i put as initial values, the results always converges only one solution. When i put that values into my equations, it fits.
Thanks.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by