필터 지우기
필터 지우기

fsolve stopped because of relative size of current step

조회 수: 13 (최근 30일)
Sanjana Singh
Sanjana Singh 2020년 6월 2일
답변: darova 2020년 6월 14일
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
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
Sanjana Singh
Sanjana Singh 2020년 6월 2일
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?

댓글을 달려면 로그인하십시오.

답변 (1개)

darova
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

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by