Maxima CAS - substitution

636 views Asked by At

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

2

There are 2 answers

0
Robert Dodier On BEST ANSWER

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
2
Fermat65537 On

The function subst (a,b,c) substitutes a for b in c. It uses 3 arguments, your first subst works because its interpreted as subst (V[b] + \epsilon*V[r],V[r], f_contin);

Your second subst is probably interpreted as subst (0,diff (V[b]*r*\rho, r),%) therefor nothing is substituted. What do you want to substitute for what?