How can I solve this set of equations using the Symbolic Toolbox?

2 views (last 30 days)
Hi guys,
I am trying to solve a set of equations for a chemical equilibrium for the concentration of H2S using the symbolics toolbox and the solve function. I have the following code. In this system, the concentrations HS, H2S and S are unknown. The equilibrium constants K1 and K2 and the concentrations H2O, H and Stot are known as well.
syms HS H2S H K1 K2 Stot S H2O;
eqns=[K1==(HS*H)/(H2O*H2S),K2==(S*H)/(H2O*HS),Stot==S+HS+H2S];
solve(eqns,H2S);
To me, this is a system that contains three unknowns and three equations. However, when running this code, it fails to find a solution for H2S. What do I need to change to make this work?
Thanks in advance for any and all help!

Accepted Answer

Walter Roberson
Walter Roberson on 28 Nov 2022
You need to solve for the same number of variables as you have equations.
  1 Comment
Joris Bergman
Joris Bergman on 28 Nov 2022
Thanks Walter!
I did not know this before, as I am new to the symbolic toolbox.
You saved me a lot of headache today :)

Sign in to comment.

More Answers (0)

Categories

Find more on Symbolic Math Toolbox in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!