fsolve message "Equation solved, inaccuracy possible"

Hi
I want to solve a system of nonlinear equations using fsolve. But I get "Equation solved, inaccuracy possible." and all x are incorrect. By changing initial guess, nothing improves!
I appreciate your help
Regards,
Fun = @xisolver1;
x0 = [1e-4 1e-4 1e-4 1e-4 1e-4 1e-2 1e-2];
% options = optimoptions('fsolve','OptimalityTolerance',1e-20, 'FunctionTolerance', 1e-20);
options = optimoptions('fsolve','Display','iter','TolFun',1e-40,'TolX',1e-40);
xr = fsolve(Fun, x0, options);
function y = xisolver1(x)
T = 31.65 + 275.15;
lnK1 = 132.899 + (-13445.9/T) + -22.4773*(log10(T)/log10(exp(1)));
lnK2 = 216.05 + (-12431.7/T) + -35.4819*(log10(T)/log10(exp(1)));
lnK3 = 231.465 + (-12092.1/T) + -36.7816*(log10(T)/log10(exp(1)));
K1 = power(exp(1),lnK1);
K2 = power(exp(1),lnK2);
K3 = power(exp(1),lnK3);
KS1 = 1/K1;
KS2 = 1/K2;
KS3 = 1/K3;
% mole
n_CO2 = 6.3746;
n_K2CO3 = 9.7119;
n_H2O = 358.8905;
n_T = n_CO2 + n_K2CO3 + n_H2O;
% mass - gr/s
m_T = 8088.2946;
% molecular weight
MW_CO2 = 44.0095;
MW_CO3 = 60.0089;
MW_HCO3 = 61.0168;
MW_OH = 17.0073;
MW_H3O = 19.0232;
MW_H2O = 18.01528;
MW_K = 39.098;
MW_K2CO3 = 138.2055;
MW_KHCO3 = 100.1151;
% mole fraction
X_CO2T = (n_CO2 + n_K2CO3)/n_T;
X_K__ = 2*(n_K2CO3/n_T);
% mole number
N_CO2T = (n_CO2 + n_K2CO3);
y(1) = K1*(x(6)^2) - 1*x(4)*x(5);
y(2) = K2*x(3)*x(6) - 1*x(5)*x(2);
y(3) = K3*x(1)*(x(6)^2) - 1*x(5)*x(3);
y(4) = x(7) + x(5) - (2*x(2) + x(3) + x(4));
y(5) = x(1) + x(2) + x(3) - ...
N_CO2T/(m_T/(x(1)*MW_CO2 + x(2)*MW_CO3 + x(3)*MW_HCO3 + x(4)*MW_OH + ...
x(5)*MW_H3O + x(6)*MW_H2O + x(7)*MW_K));
y(6) = x(1) + x(2) + x(3) + x(4) + x(5) + x(6) + x(7) - 1;
y(7) = x(7) - (2*n_K2CO3)/(m_T/(x(1)*MW_CO2 + x(2)*MW_CO3 + x(3)*MW_HCO3 + x(4)*MW_OH + ...
x(5)*MW_H3O + x(6)*MW_H2O + x(7)*MW_K));

2 comentarios

John D'Errico
John D'Errico el 26 de Abr. de 2019
Editada: John D'Errico el 26 de Abr. de 2019
You should understand that
log10(T)/log10(exp(1))
is equivalent to the simple
log(T)
That is, log(T) is the NATURAL LOG of T?\
As well, why would you do this?
K1 = power(exp(1),lnK1);
You seem to understand that exp(1) yields the number e. So just use
K1 = exp(lnK1);
sina
sina el 26 de Abr. de 2019
You're absolutly right, I modified that.
Do you have any idea about the question?

Iniciar sesión para comentar.

 Respuesta aceptada

Matt J
Matt J el 18 de Sept. de 2018
Editada: Matt J el 18 de Sept. de 2018
But the solution you got solves the equations quite well and also zeros the optimality measure quite well. If the wrong solution solves the equations, then the equations are to blame.
Norm of First-order Trust-region
Iteration Func-count f(x) step optimality radius
0 8 0.959589 1 1
1 16 2.73535e-08 0.901598 2.81e-06 1
2 24 5.66403e-09 0.0230512 1.72e-06 2.25
3 32 1.82444e-11 0.00549156 9.15e-08 2.25
4 40 3.05915e-16 0.000351564 3.73e-10 2.25
5 48 8.60818e-21 0.000134172 3.73e-13 2.25

4 comentarios

sina
sina el 18 de Sept. de 2018
Editada: Matt J el 18 de Sept. de 2018
Hi Matt,
I got the same solution with the following message
Equation solved, inaccuracy possible.
The vector of function values is near zero, as measured by the selected value
of the function tolerance. However, the last step was ineffective.
<stopping criteria details>
In order to check the accuracy of the x, I solve y(1) to get K1, but K1 is not the same as used in the previous calculation. This can be seen for K2 and K3. Because of that, I need to improve the x(1..7). But How, it's my question, even I tried to eleminate x(1,3,6) but still was not accurate!
Matt J
Matt J el 18 de Sept. de 2018
Editada: Matt J el 18 de Sept. de 2018
Try increasing the weight on the first 3 equations
y(1) = K1*(x(6)^2) - 1*x(4)*x(5);
y(2) = K2*x(3)*x(6) - 1*x(5)*x(2);
y(3) = K3*x(1)*(x(6)^2) - 1*x(5)*x(3);
y(1:3)=1e12*y(1:3);
sina
sina el 18 de Sept. de 2018
Editada: sina el 18 de Sept. de 2018
This worked better, However, because of K value I don't know maybe this is normal, and we can accept x
sina
sina el 18 de Sept. de 2018
It worked however I got "Equation solved, inaccuracy possible." but I think for my case I can ignore the error!

Iniciar sesión para comentar.

Más respuestas (1)

Alex Sha
Alex Sha el 22 de Abr. de 2019
Multi-solutions:
1:
x1: 1.00788811123075E-6
x2: 0.0083586258586415
x3: 0.0330975342164431
x4: 0.000243072462467804
x5: 4.25824266670525E-13
x6: 0.908241901178143
x7: 0.0500578583957681
2:
x1: 0.0398069369652828
x2: 4.09226387610729E-13
x3: -6.59445321197498E-9
x4: -7.80181990889573E-15
x5: -0.0480652696493024
x6: 0.960193076222411
x7: 0.0480652630556597
3:
x1: -0.00867531212733977
x2: 3.28114366134408E-10
x3: 0.0504921742289807
x4: -1.14968645806141E-9
x5: -1.22255237713138E-9
x6: 0.907690964984408
x7: 0.0504921749580755

2 comentarios

sina
sina el 26 de Abr. de 2019
x should be positive. How did you solve it?
Positive solution:
x1: 2.69509999486066E-5
x2: 0.00844390016219942
x3: 0.0329852412877576
x4: 0.000183518150344329
x5: 5.65645880096964E-12
x6: 0.908303829637249
x7: 0.0500565597568442

Iniciar sesión para comentar.

Categorías

Preguntada:

el 18 de Sept. de 2018

Comentada:

el 28 de Sept. de 2024

Community Treasure Hunt

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

Start Hunting!

Translated by