fsolve no solution found.
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi everybody, I'm trying to resolve a system equation with the fsolve() command. The problem is that if I choose a different value for the addictional parameter the solution converge until a certain value. For a value below 2.3e3 the solution converge,instead for a value above: "fsolve stopped because the problem appears regular as measured by the gradient, but the vector of function values is not near zero as measured by the default value of the function tolerance."
Ptot = 2.3e4;
x0 = [10 10];
P=Ptot;
f = @(X)myfunFC(X,P);
options = optimset('MaxFunEvals',10000,'MaxIter',10000);
[x,fval,exitflag] = fsolve(f,x0,options);
The function myfunFC is:
function F = myfunFC(X,P)
G0 = 237*10^3;
F = 96485.3415;
E0 = G0/(2*F);
T = 25+273.15;
R = 8.314;
pH2 = 5;
pO2 = 5;
A=0.03;
r=0.000245;
m=2.11E-5;
n=0.008;
i0 = 0.01;
i= 0.01:0.1:1500;
E = E0 + ((R*T)/(2*F))*log(pH2*pO2^0.5);
Eoc = E + A*log(i0);
C = 0.06;
PO1=1;
PO2=5;
DeltaVgain = C*log(PO2/PO1);
T1 = 25+273.15;
eta_m = 0.9;
eta_c= 0.7;
lambda = 2;
Pratio=PO2/PO1;
Vloss = 3.58*10^(-4)*(15/(eta_m*eta_c))*(Pratio^0.286 - 1)*lambda;
i = X(1);
Vtot = X(2);
F(1)= Vtot - ((Eoc - r*i - A*log(i) - m*exp(n*i))+DeltaVgain -Vloss);
F(2)= P-24*(Vtot*i)*10^(-3)*232;
I tried to change the initial value but the problem still the same.
4 Kommentare
Walter Roberson
am 2 Aug. 2011
Please avoid using a variable named "i", as "i" can also mean the square root of negative one.
Antworten (1)
John D'Errico
am 9 Nov. 2020
Bearbeitet: John D'Errico
am 9 Nov. 2020
Consider this simple function of one variable.
fun = @(x) (x-1).*exp(-x) + 0.5;
fplot(fun,[0,10])
yline(0);
grid on
As you can see, there is a root roughly at x = 0.3. What happens if we start fsolve near there?
[xsol,fsol,exitfflag] = fsolve(fun,1)
So fsolve was happy, finding the expected solution. Any starting value less than 2 would seem to result in the desired solution.
But what happens if we start fsolve in a bad place?
[xsol,fsol,exitfflag] = fsolve(fun,3)
So fsolve knows it has not found a solution. It keeps trying to reduce the function by increasing x. But clearly, you can see this will never work. Eventually, fsolve gives up, around x==16.5 as you can see. There the function is quite close to a constant.
format long g
fun(16.5 + [0 .1 .2])
As you can see, fun is asymptotically approaching a constant.
No matter how large x is made, fun(x) will continuously decrease, but it will never be less that 0.5. fsolve does not understand what the function does, or that it needed to look below x==2.
This is the same behaviour you saw, although in a simple function we can easily visualize.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Historical Contests finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!