I am wondering if there is a way to simplify an algebraic expression given a known variable equation using Mathematica. For instance, I wish to simplify an expression for the heat change in a process:

$$\Delta Q = \frac{p_{1}C_{p}}{R}(V_{2}-V_{1})+\frac{V_{2}C_{V}}{R}(p_{2}-p_{1})$$

Given that I know the following is true:

$$p_{1}V_{1}^{\gamma}=p_{2}V_{2}^{\gamma} \land \gamma\triangleq \frac{C_p}{C_V}$$

Is there a way to do this in Mathematica? I tried using:

FullSimplify[((p_1 C_p)/R)(V_2-V_1) + ((V_2 C_V)/R)(p_2 - p_1), Assumptions->{p_1 V_1^(gamma) == p_2 V_2^(gamma),gamma==C_p/C_V}]

But it didn't work, it worked as though there were no assumptions present.


2 Answers 2


First of all, the underscore is not allowed in a variable name. Your expression can be written in Mathematica for instance format like this

FullSimplify[((p1 Cp)/R) (V2 - V1) + ((V2 CV)/R) (p2 - p1), 
 Assumptions -> {p1 V1^(gamma) == p2 V2^(gamma), gamma == Cp/CV}]

(* Out[70]= (CV (-p1 + p2) V2 + Cp p1 (-V1 + V2))/R *)

Next, even though it sounds tempting, Assumtions is not the correct way to deal with your problem. At least, how should Mathematica know which variable you wish to replace?

This is how you can do it.

You expression is

f = ((p1 Cp)/R) (V2 - V1) + ((V2 CV)/R) (p2 - p1)

(* Out[1]= (CV (-p1 + p2) V2)/R + (Cp p1 (-V1 + V2))/R *)

The relation between the variables is an equation

eq = p1 V1^(gamma) == p2 V2^(gamma);

Solve it for, say p2 and put the result in x:

x = p2 /. Solve[p1 V1^(gamma) == p2 V2^(gamma), p2][[1]]

(* Out[2]= p1 V1^gamma V2^-Gamma *)

Now put the result into your expression f:

f1 = f /. p2 -> x

(* Out[3]= (Cp p1 (-V1 + V2))/R + (CV V2 (-p1 + p1 V1^gamma V2^-gamma))/R *)

If you wish you can also replace gamma by the ratio of the specific heat coefficients:

f2 = f1 /. gamma -> Cp/CV

(* Out[4]= (Cp p1 (-V1 + V2))/R + (CV V2 (-p1 + p1 V1^(Cp/CV) V2^(-(Cp/CV))))/R *)

Of course, you can chose another variable to be replaced. Try to eliminate V2 which is slightly tricker.

Best regards, Wolfgang

  • $\begingroup$ Dear Wolfgang, thank you for your prompt reply. I didn't put the underscores in the Mathematica input, they were to denote the subscripts that I used, but I understand that wasn't clear. Thank you for explaining the process, I was wondering if there was an automated way, but your reasoning for why not makes perfect sense! $\endgroup$ Commented Nov 10, 2014 at 13:26

Eliminate seems to work well. Stealing @Wolfgang's expressions:

eqs = DeltaQ == ((p1 Cp)/R) (V2 - V1) + ((V2 CV)/R) (p2 - p1)
given = {p1 V1^(gamma) == p2 V2^(gamma), gamma == Cp/CV}

If you want to eliminate p2

Eliminate[{eqs}~Join~ given, {p2}] // Solve[#, DeltaQ] & // FullSimplify

{{DeltaQ$\to \frac{\text{p1} \left(\text{Cp} (\text{V2}-\text{V1})+\text{CV} \text{V2} \left(\text{V1}^{\text{gamma}} \text{V2}^{-\text{gamma}}-1\right)\right)}{R}$}}

And if you don't want a expressions on your answers, you can tell Mathematica that they are a variable. Removing gamma from the above expression:

Eliminate[{eqs}~Join~ given, {p2}] // Solve[#, {DeltaQ, gamma}] & // FullSimplify

{{DeltaQ $\to \frac{\text{p1} \left(\text{CV} \text{V2} \left(\text{V1}^{\text{Cp}/\text{CV}} \text{V2}^{-\frac{\text{Cp}}{\text{CV}}}-1\right)+\text{Cp} (\text{V2}-\text{V1})\right)}{R}$}}

In general, if you Eliminate variables you get simpler answers.

Eliminate[{eqs}~Join~ given, {p2}];
Eliminate[{%}~Join~ given, {gamma}];
% // Solve[#, DeltaQ] &;
% // FullSimplify;

{{Delta$\to \frac{\text{Cp} \text{p1} (\text{V2}-\text{V1})+\text{CV} \text{V2} (\text{p2}-\text{p1})}{R}$}}

Disclaimer: I couldn't make Mathematica prove that those last two equations were equivalent, so there could be an error there!

Stealing again from @Wolfgang's answer, if you want to eliminate V2:

Eliminate[{eqs}~Join~given, {V2}] // Solve[#, {DeltaQ}] & // FullSimplify

{{DeltaQ$\to \frac{\text{CV} ((\text{gamma}-1) \text{p1}+\text{p2}) \left(\frac{\text{p1} \text{V1}^{\text{gamma}}}{\text{p2}}\right)^{1/\text{gamma}}-\text{CV} \text{gamma} \text{p1} \text{V1}}{R}$}}

Again, do not use those blindly. If you have some numbers to plug and check the equivalence, please use them!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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