fsolve stopped because of relative size of current step
13 views (last 30 days)
Show older comments
I am trying to solve an equation using fsolve and I am getting the following error-
"fsolve stopped because the relative size of the current step is less than the
default value of the step size tolerance, but the vector of function values
is not near zero as measured by the default value of the function tolerance."
I am getting "No solution" even when I know that I should be getting a solution for all real values of psi. Can someone help me figure out what I need to change to get solutions.
syms y
psi = 0.1515;
r = 0.3;
a = r;
vf = [5 0];
m = 1;
x = linspace(-10*r,10*r);
x0 = ones(1,size(x,2));
opts = optimoptions(@fsolve,'Algorithm', 'levenberg-marquardt');
y = fsolve(@(y_val)solve_y(y_val,a,vf,x,psi,m),x0,opts);
% function solve_y
function F = solve_y(y_val,a,vf,x,psi,m)
y = y_val;
F = psi./norm(vf) - y - m*atan2(y,x+a) - m*atan2(y,x-a);
end
2 Comments
Alan Weiss
on 2 Jun 2020
I'm not at all sure that I understand what you are doing. Are you trying to solve for a bunch of scalar roots all at once, or is your objective really vector-valued? Why do you have a syms y call at the start of your script?
Alan Weiss
MATLAB mathematical toolbox documentation
Answers (1)
darova
on 14 Jun 2020
use for loop
syms y
psi = 0.1515;
r = 0.3;
a = r;
vf = [5 0];
m = 1;
x = linspace(-10*r,10*r);
x0 = ones(1,size(x,2));
F = @(y,x) psi./norm(vf) - y - m*atan2(y,x+a) - m*atan2(y,x-a);
opts = optimoptions(@fsolve,'Algorithm', 'levenberg-marquardt');
for i = 1:length(x)
y0 = fsolve(@(y)F(y,x(i)),x(i));
line(x(i),y,'markerk','*')
end
0 Comments
See Also
Categories
Find more on Symbolic Math Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!