Computer specific fsolve error
Show older comments
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 Comment
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
Answers (0)
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!