fsolve message "Equation solved, inaccuracy possible"

19 ビュー (過去 30 日間)
sina
sina 2018 年 9 月 18 日
コメント済み: sina 2019 年 4 月 26 日
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 件のコメント
John D'Errico
John D'Errico 2019 年 4 月 26 日
編集済み: John D'Errico 2019 年 4 月 26 日
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 2019 年 4 月 26 日
You're absolutly right, I modified that.
Do you have any idea about the question?

サインインしてコメントする。

採用された回答

Matt J
Matt J 2018 年 9 月 18 日
編集済み: Matt J 2018 年 9 月 18 日
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 件のコメント
sina
sina 2018 年 9 月 18 日
編集済み: sina 2018 年 9 月 18 日
This worked better, However, because of K value I don't know maybe this is normal, and we can accept x
sina
sina 2018 年 9 月 18 日
It worked however I got "Equation solved, inaccuracy possible." but I think for my case I can ignore the error!

サインインしてコメントする。

その他の回答 (1 件)

Alex Sha
Alex Sha 2019 年 4 月 22 日
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
  1 件のコメント
sina
sina 2019 年 4 月 26 日
x should be positive. How did you solve it?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeIntroduction to Installation and Licensing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by