fsolve yields initial guess as solution to non-linear equation

21 Ansichten (letzte 30 Tage)
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.

Akzeptierte Antwort

Davide Masiello
Davide Masiello am 13 Feb. 2022
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.

Weitere Antworten (1)

Saeid
Saeid am 14 Feb. 2022
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.

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by