fsolve stopped because of relative size of current step

13 views (last 30 days)
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
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
Sanjana Singh
Sanjana Singh on 2 Jun 2020
Yes, I forgot to eliminate the syms, thank you for pointing that out. I have a single equation in which I need to solve for y having all other values i.e psi, vf, a, m and a range of values for x. I wish to get a single y value corresponding to a each x value by solving the given equation (F = 0). Does this help?

Sign in to comment.

Answers (1)

darova
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

Community Treasure Hunt

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

Start Hunting!