fsolve yields initial guess as solution to non-linear equation

11 次查看(过去 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.

采纳的回答

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