Solving system of 4 equation

I need assistance with solving these 4 equations in MATLAB as I am unsure of how to code them. Can someone please help me? It's worth mentioning that all variables, except for e1, e2, e3, and e4, are known, and K(i), k2(i), k3(i), and k4(i) are matrices consisting of 25 values.
0=((nco+v3*e1+v22*e2+v41*e4)^2*(nh2+v4*e1+v24*e2+v33*e3)^2)-(k(i)*(n0+v*e1+v03*e3+v04*e4)^2*(nch4+v1*e1+v31*e3)*(nco2+v2*e1+v23*e2+v42*e4));
0=((nco+v3*e1+v22*e2+v41*e4)*(nh2o+v21*e2)-(k21(i)*(nco2+v2*e1+v23*e2+v42*e4)*(nh2+v4*e1+v24*e2+v33*e3)));
0=((nh2+v4*e1+v24*e2+v33*e3)^2-(k31(i)*(n0+v*e1+v03*e3+v04*e4)*(nch4+v1*e1+v31*e3)));
0=((n0+v*e1+v03*e3+v04*e4)*(nco2+v2*e1+v23*e2+v42*e4)-(k41(i)*(nco+v3*e1+v22*e2+v41*e4)^2));

Réponses (1)

Torsten
Torsten le 19 Mai 2023
Modifié(e) : Torsten le 19 Mai 2023

0 votes

Try "fsolve":
e0 = [e10;e20;e30;e40]; % initial guesses
for i = 1:25
fun = @(e1,e2,e3,e4) [((nco+v3*e1+v22*e2+v41*e4)^2*(nh2+v4*e1+v24*e2+v33*e3)^2)-(k(i)*(n0+v*e1+v03*e3+v04*e4)^2*(nch4+v1*e1+v31*e3)*(nco2+v2*e1+v23*e2+v42*e4));...
((nco+v3*e1+v22*e2+v41*e4)*(nh2o+v21*e2)-(k21(i)*(nco2+v2*e1+v23*e2+v42*e4)*(nh2+v4*e1+v24*e2+v33*e3)));...
((nh2+v4*e1+v24*e2+v33*e3)^2-(k31(i)*(n0+v*e1+v03*e3+v04*e4)*(nch4+v1*e1+v31*e3)));...
((n0+v*e1+v03*e3+v04*e4)*(nco2+v2*e1+v23*e2+v42*e4)-(k41(i)*(nco+v3*e1+v22*e2+v41*e4)^2))];
sol(i,:) = fsolve(@(x)fun(x(1),x(2),x(3),x(4)),e0);
end

2 commentaires

nima
nima le 19 Mai 2023
Thanks for your response but I think these equations have more than one answers for each unkonwn variables. How can I find and see the other answers?
Torsten
Torsten le 20 Mai 2023
Modifié(e) : Torsten le 20 Mai 2023
You can try different initial values for the unknowns and MultiStart, but there is no guarantee to find all solutions.

Connectez-vous pour commenter.

Question posée :

le 19 Mai 2023

Modifié(e) :

le 20 Mai 2023

Community Treasure Hunt

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

Start Hunting!

Translated by