1
$\begingroup$

I am trying to use Mathematica to solve a system of 8 equations, but am not sure how to accomplish this. One of the issues is that when I do the work by hand a quadratic equation forms through solving. I have tried to solve in Mathematica a number of ways. Essentially, I want to solve for the variable r (in the very last equation), so that it is in terms of only P, k and K variables (no t variables), but when I launch this code, all Mathematica does is tell me what subscripts are. Any suggestions?

Solve{{a=k/(t*r),
b=p/(u*r),
1=r+q,
(1/2)(g*o*r-h*p*q)=i*k*p-j*m*r, 
w=l*o/(m*p), 
x=l/(s*r), 
f=v*r^2/q^2, 
z =(1/2)(1/2)(g*o*r-h*p*q)}, 
{z}}
$\endgroup$
  • 1
    $\begingroup$ Using subscripts in computational work is often a great bother. Save them for formatting, and use different variables instead. $\endgroup$ – J. M. is away Feb 1 '17 at 1:37
  • 1
    $\begingroup$ ...and please post code that can be copied. $\endgroup$ – David G. Stork Feb 1 '17 at 1:51
  • $\begingroup$ I will try that J.M. I am not sure how you can make the code copyable without highlighting then copying. I assume you mean it should be clicked easily to copy? I will work this out next time. Thanks. $\endgroup$ – ChemE52 Feb 1 '17 at 1:56
  • $\begingroup$ The main suggestion is to post something that cuts-and-pastes as runnable code. $\endgroup$ – Daniel Lichtblau Feb 1 '17 at 2:12
  • 1
    $\begingroup$ For odd reasons, if you have n equations then it is often faster to solve for n of those variables, not just one variable. Thus Solve[{a==k/(t* r),...rest of your equations using the same form...},{a, b, r, i, w, x, f, z}] almost instantly returns with the values of those 8 variables, including the value for z. $\endgroup$ – Bill Feb 1 '17 at 4:54
1
$\begingroup$

I would always have the same number of equations and variables you are solving for. You want to solve for r but not in terms of ts, which means you need to treat ts as additional variables for solving.

Using your unedited set of equations, so that we know what variables to solve for:

FullSimplify[
  r /. Solve[
    {
      K1 == tCO/(PCO*ts),
      K2 == tH2O/(PH2O*ts),
      1 == ts + tH,
      (1/2) (k3*tH2O*ts - km3*tOH*tH) == k4*tCO*tOH - km4*tCOOH*ts,
      K5 == tCO2*tH2O/(tCOOH*tOH),
      K6 == tCO2/(PCO2*ts),
      K7 == PH2*ts^2/tH^2,
      r == (1/2) (k3*tH2O*ts - km3*tOH*tH)
    },
  {tCO, tH2O, ts, tH, tOH, tCO2, tCOOH, r} (* all vars that you are solving for *)
  ],
  Assumptions -> {K1, K2, k3, km3, k4, km4, K5, K6, K7, PCO, PH2O, PCO2, PH2} > 0
]

If you paste this in Mathematica, you will notice all vars you are solving for will have a teal colour and you will end up with your answer in terms of variables that are blue.

Solve gave me quite complicated formulas, so I tried to simplify it, but I'm not sure what your assumptions are - change accordingly.

$\endgroup$
  • $\begingroup$ I really appreciate everyone's feedback! mszynisz, what you have here makes sense, and it will give me a great template for doing problems in the future. I realize this is probably silly, but is there a way to specify to Mathematica that I specifically want to do math? For example, with the code you created, Mathematica interprets tCO and PCO as stock market names, and outputs financial trade data. Is this some sort of setting I need to correct? $\endgroup$ – ChemE52 Feb 1 '17 at 7:20
  • $\begingroup$ Ah, I figured out how to do it now... right now I am finding it amazing that I have ever learned other programming languages :) $\endgroup$ – ChemE52 Feb 1 '17 at 7:30
  • 1
    $\begingroup$ @ChemE52 In Mathematica, if you press "=" in the beginning of your cell, it sends it to WolframAlpha. And I'm guessing it's WolframAlpha that interpreted some of your symbols as financial trade data. $\endgroup$ – mszynisz Feb 1 '17 at 7:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.