fsolve stopped because of relative size of current step
12 次查看(过去 30 天)
显示 更早的评论
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 个评论
Alan Weiss
2020-6-2
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
回答(1 个)
darova
2020-6-14
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Calculus 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!