Computer specific fsolve error
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
1 commentaire
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]
fun = @(x) sin(x) + 2.*x.*cos(x);
for i =1:numel(x0)
lamda(i) = lsqnonlin(fun,sqrt(x0(i)),0,[]).^2;
end
lamda
Réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!