Computer specific fsolve error

2 vues (au cours des 30 derniers jours)
Benjamin Linehan
Benjamin Linehan le 2 Fév 2023
Modifié(e) : Matt J le 2 Fév 2023
I am encountering an error using the fsolve function that appears to be specific to my computer. The code below runs perfectly fine on other computers (and when I paste it in here annoyingly) but when I run it on my machine I get the errors shown below. I was originally on matlab R2019a and have since updated to R2022b to try and fix the issue but I am still seeing the same errors.
Error Messages from command prompt:
Error using formatFsolveMessage
'optim:fsolve:Exit100basic' is an invalid option
Error in fsolve (line 457)
[EXITFLAG,OUTPUT.message] = formatFsolveMessage(Resnorm,sqrtTolFunValue,EXITFLAG, ...
Error in Rec3 (line 15)
lamda(i) = fsolve(@(l) fun(l),x0(i)) - Show complete stack trace
Code:
n = 4;
l = linspace(0,150,10000);
% approx the roots
x0 = [0,3,37,23.15,62.67];
fun = @(l) sin(sqrt(l)) + 2.*sqrt(l).*cos(sqrt(l));
for i =1:n
lamda(i) = fsolve(@(l) fun(l),x0(i))
end
Equation solved at initial point. fsolve completed because the vector of function values at the initial point is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient.
lamda = 0
Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient.
lamda = 1×2
0 3.3731
Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient.
lamda = 1×3
0 3.3731 23.1923
Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient.
lamda = 1×4
0 3.3731 23.1923 23.1923
  1 commentaire
Matt J
Matt J le 2 Fév 2023
Modifié(e) : Matt J le 2 Fév 2023
I don't recognize the error message, but the problem formulation has issues. You should be using lsqnonlin to impose positiveity constraints, and you should remove the sqrt() operations, because they are non-differentiable,
x0 = [0,3,37,23.15,62.67]
x0 = 1×5
0 3.0000 37.0000 23.1500 62.6700
fun = @(x) sin(x) + 2.*x.*cos(x);
for i =1:numel(x0)
lamda(i) = lsqnonlin(fun,sqrt(x0(i)),0,[]).^2;
end
Initial point is a local minimum. Optimization completed because the size of the gradient at the initial point is less than the value of the optimality tolerance. Local minimum found. Optimization completed because the size of the gradient is less than the value of the optimality tolerance. Local minimum found. Optimization completed because the size of the gradient is less than the value of the optimality tolerance. Local minimum found. Optimization completed because the size of the gradient is less than the value of the optimality tolerance. Local minimum found. Optimization completed because the size of the gradient is less than the value of the optimality tolerance.
lamda
lamda = 1×5
0 3.3731 23.1923 23.1923 62.6797

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by