# fsolve yields initial guess as solution to non-linear equation

14 visualizzazioni (ultimi 30 giorni)
Saeid il 13 Feb 2022
Risposto: Saeid il 14 Feb 2022
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 CommentiMostra -1 commenti meno recentiNascondi -1 commenti meno recenti

Accedi per commentare.

### Risposta accettata

Davide Masiello il 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.
##### 0 CommentiMostra -1 commenti meno recentiNascondi -1 commenti meno recenti

Accedi per commentare.

### Più risposte (1)

Saeid il 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.
##### 0 CommentiMostra -1 commenti meno recentiNascondi -1 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Solver Outputs and Iterative Display in Help Center e File Exchange

R2021b

### Community Treasure Hunt

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

Start Hunting!