fsolve yields initial guess as solution to non-linear equation
조회 수: 15 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
채택된 답변
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.
댓글 수: 0
추가 답변 (1개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!