Search code examples
mathphysicsmaxima

Solving physics problems symbolically with Maxima


I am trying to solve some basic physics problems using Maxima, but I am running into problems.

I want the code below to yield 600 (as the solution to T2), but it just gives an empty list ([]).

solve([
    (P1*V1)/T1 = (P2*V2)/T2,
    V1 = V2,
    P1 = 100000,
    T1 = 300,
    P2 = 200000
    ], [T2]);

What am I missing? (I also tried many other problems similar to this one, and they all seem to fail.)

I know that I could solve this particular one numerically, but I want the answers to be precise, and I also want to be able to solve problems like this:

solve([
    (P1*V1)/T1 = (P2*V2)/T2,
    V1 = V2
    ], [T2]);

(Where the solution should be (T1*P2)/P1.)


Solution

  • There are a few different ways to go about it. Let's start with:

    (%i1) eqn : (P1*V1)/T1 = (P2*V2)/T2 $
    (%i2) myvalues : [V1 = V2,P1 = 100000,T1 = 300,P2 = 200000] $
    

    (1) Substitute values into the equation and then solve the equation.

    (%i3) subst (myvalues, eqn);
                                  1000 V2   200000 V2
    (%o3)                         ------- = ---------
                                     3         T2
    (%i4) solve (%, T2);
    (%o4)                             [T2 = 600]
    

    (2) Solve the equation in general and then substitute values into the solution.

    (%i5) solve (eqn, T2);
                                          P2 T1 V2
    (%o5)                           [T2 = --------]
                                           P1 V1
    (%i6) subst (myvalues, %);
    (%o6)                             [T2 = 600]
    

    (3) Solve the equation with values temporarily assigned to variables.

    (%i7) ev (solve (eqn, T2), myvalues);
    (%o7)                             [T2 = 600]
    

    or, equivalently (this formulation is seen pretty often):

    (%i8) solve (eqn, T2), V1 = V2,P1 = 100000,T1 = 300,P2 = 200000;
    (%o8)                             [T2 = 600]
    

    (2) is perhaps the most general way to go about it. (1) and (3) are more or less equivalent in the sense that the variables already have values assigned by the time solve sees the equation. That can often make the equation easier for solve to solve it.

    In addition to solve, take a look at to_poly_solve to solve equations.