Search code examples
maxima

Maxima CAS - substitution


I am trying to simplify a differential equation via substitution in maxima. However, the substitution does not seem to be working.

Here's my code:

depends (\rho,[t, r, \theta, z]); depends (V, [t, r, \theta, z]);
f_contin : diff (\rho, t) + diff (\rho*r*V[r], r)*(1/r) = 0;
base : diff (V[b]*r*\rho, r) = 0;
V_sub : V[r] = V[b] + \epsilon*V[r];
subst (V_sub, f_contin);
subst (base, %o6);

The last substitution did not work. What am I doing wrong here?

For clarity I add a Screenshot here: enter image description here


Solution

  • The problem is that subst(a=b, c) (or equivalently subst(b, a, c)) can only make substitutions when a is an exact subexpression of c.

    ratsubst (which see) can handle some cases when a is not an exact subexepression but in this case it doesn't seem to work.

    But I think you can get the result you want by just subtracting the one equation from the other. Note that (a=b) - (c=d) yields a - c = b - d. Note also that I've put in another step (in %i7) to apply the diff operator. Also I've multiplied %o7 by r to get something like base.

    (%i1) depends (\rho,[t, r, \theta, z]); depends (V, [t, r, \theta, z]);
    (%o1)                        [rho(t, r, theta, z)]
    (%o2)                         [V(t, r, theta, z)]
    (%i3) f_contin : diff (\rho, t) + diff (\rho*r*V[r], r)*(1/r) = 0;
                                drho      d
                           r V  ---- + r (-- (V )) rho + V  rho
                    drho      r  dr       dr   r          r
    (%o3)           ---- + ------------------------------------ = 0
                     dt                     r
    (%i4) base : diff (V[b]*r*\rho, r) = 0;
                            drho    d
    (%o4)              V  r ---- + (-- (V )) r rho + V  rho = 0
                        b    dr     dr   b            b
    (%i5) V_sub : V[r] = V[b] + \epsilon*V[r];
    (%o5)                        V  = epsilon V  + V
                                  r            r    b
    (%i6) subst (V_sub, f_contin);
          drho                        drho      d
    (%o6) ---- + (r (epsilon V  + V ) ---- + r (-- (epsilon V  + V )) rho
           dt                 r    b   dr       dr           r    b
                                                     + (epsilon V  + V ) rho)/r = 0
                                                                 r    b
    (%i7) %o6, nouns;
          drho                        drho               d          d
    (%o7) ---- + (r (epsilon V  + V ) ---- + r (epsilon (-- (V )) + -- (V )) rho
           dt                 r    b   dr                dr   r     dr   b
                                                     + (epsilon V  + V ) rho)/r = 0
                                                                 r    b
    (%i8) expand (r*%o7 - base);
            drho                drho              d
    (%o8) r ---- + epsilon r V  ---- + epsilon r (-- (V )) rho + epsilon V  rho = 0
             dt               r  dr               dr   r                  r