Borrar filtros
Borrar filtros

fsolve no solution found.

10 visualizaciones (últimos 30 días)
Mario
Mario el 2 de Ag. de 2011
Editada: John D'Errico el 9 de Nov. de 2020
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 comentarios
Walter Roberson
Walter Roberson el 2 de Ag. de 2011
Please avoid using a variable named "i", as "i" can also mean the square root of negative one.
Mario
Mario el 2 de Ag. de 2011
You are right, I changed with "I" but the problem still not resolve it.

Iniciar sesión para comentar.

Respuestas (1)

John D'Errico
John D'Errico el 9 de Nov. de 2020
Editada: John D'Errico el 9 de Nov. de 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)
Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient.
xsol = 0.3149
fsol = -2.5123e-07
exitfflag = 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)
No solution found. 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 value of the function tolerance.
xsol = 16.5000
fsol = 0.5000
exitfflag = -2
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])
ans = 1×3
0.500001057968523 0.500000963465568 0.500000877368029
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.

Categorías

Más información sobre Historical Contests en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by