필터 지우기
필터 지우기

fsolve yields initial guess as solution to non-linear equation

조회 수: 10 (최근 30일)
Saeid
Saeid 2022년 2월 13일
답변: Saeid 2022년 2월 14일
I am currently trying to solve a non-linear equation using the following program:
clc; format long g;
a=0.5; Eta0=100; t12=1e6; q=2e-7; R=0.001;
x0=8e5;
Px=F1(q,Eta0,a,t12,R,x0)
function Px=F1(q,Eta0,a,t12,R,x0)
A=pi*(R^4)/(8*Eta0); B=4/(3+a); C=0.5*R/t12;
[x,fval]=fsolve(@(x) FX1(x,A,B,C,a),x0);
Px=x;
function fx1=FX1(x,A,B,C,a)
fx1=A*x*(1+B*(C*x)^(a-1))-q;
end
end
But no matter what value of initial guess I choose, the program always gives THAT value as the root of this equation. Here the soultion would be x=1e6, but the program yields any value that I enter as x0, which in this case is 8e5.
I have tested the routine with solutions that are smaller numbers (order of magnitude of (1-10), but when the solutions becomes a relatively large number this problem occurs.

채택된 답변

Davide Masiello
Davide Masiello 2022년 2월 13일
Try with this syntax
clc, format long g
a = 0.5;
Eta0 = 100;
t12 = 1e6;
q = 2e-7;
R = 0.001;
x0 = 14e5;
Px = fzero(@(x)F1(x,q,Eta0,a,t12,R),x0);
disp(Px)
disp(Px-x0)
function out=F1(x,q,Eta0,a,t12,R)
A=pi*(R^4)/(8*Eta0);
B=4/(3+a);
C=0.5*R/t12;
out=A*x*(1+B*(C*x)^(a-1))-q;
end
Now the value found is always the same regardless of x0, provided that x0 is not too far from the root.

추가 답변 (1개)

Saeid
Saeid 2022년 2월 14일
Thank you Davide! This really works, although it is not completely indpendent from the initial guess. Of course I know that an intelligent first guess is always part of the solution, but this routine was supposed to be part of a loop, where the value of Px is calculated for a range of q parameters that runs in the said loop.
Anyway, I still cannot figure out why fsolve cannot solve this problem the way fzero does.

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by