\( \DeclareMathOperator{\abs}{abs} \newcommand{\ensuremath}[1]{\mbox{$#1$}} \)

Differentials

 1 Defining the Differential

We know that the differential for a function f(x) is given by df = f'(x)dx.  So we must take the derivative of f(x), and then multiply it by dx.  As it turns out, Maxima can do this automatically for us if we use the diff() command *without* giving the variable of
differentiation.  For example:

--> diff(x^2);
\[\tag{%o1} 2 x \operatorname{del}(x)\]

The del(x) symbol is Maxima's symbol for the differential "dx".  Note that if we had used a different variable, we would have:

--> diff(s^3+2*s);
\[\tag{%o2} \left( 3 {{s}^{2}}+2\right) \operatorname{del}(s)\]

If we had defined a function f(x) first, then:

--> f(x):=cos(x);
diff(f(x));
\[\tag{%o3} \operatorname{f}(x):=\cos{(x)}\] \[\tag{%o4} -\sin{(x)} \operatorname{del}(x)\]

 2 Evaluating the Differential

Now let's attempt to find the differential of f(x)=x^2 for x=1 and dx=0.1.  We know that the answer
should be: df = 2xdx = 2(1)(0.1) = 0.2.  Here's how we do it:

--> df:diff(x^2);
\[\tag{df}2 x \operatorname{del}(x)\]
--> subst([del(x)=0.1,x=1],df);
\[\tag{%o6} 0.2\]

That's it!  Or in one line:

--> subst([del(x)=0.1,x=1],diff(x^2));
\[\tag{%o7} 0.2\]

All that we did in the above is compute the differential, then substitute the values in for del(x) and x.

 2.1 Caution: Order of Substitution Matters!

Maxima views del(x) as a compound expression of both del and x.  So if we substitute x first, this
will cause problems:

--> subst([x=1,del(x)=0.1],diff(x^2));
\[\tag{%o8} 2 \operatorname{del}(1)\]

What?!!  Note that because we put in the x value first as 1, del(x) → del(1), and there is no longer
a del(x) to be substituted for!  To ensure that this doesn't happen, we must substitute for any
del() expressions first!

 3 Differentials of Formulae

Suppose that we have a formula for volume that depends on two parameters, but only one of them
is playing the role of a variable, like:

--> V(r):=%pi*r^2*h;
\[\tag{%o9} \operatorname{V}(r):=\ensuremath{\pi} {{r}^{2}} h\]

This gives the volume of a cylinder of height h and radius r.  Here h is a constant, but when we
compute:

--> diff(V(r));
\[\tag{%o10} 2 \ensuremath{\pi} h r \operatorname{del}(r)+\ensuremath{\pi} {{r}^{2}} \operatorname{del}(h)\]

Maxima doesn't know that h is supposed to be a constant and includes it in the computation
of the differential. One way that we can tell Maxima that h is constant is to let it know that
h is not changing.  That is, del(h)=0:

--> subst(del(h)=0,diff(V(r)));
\[\tag{%o16} 2 \ensuremath{\pi} h r \operatorname{del}(r)\]

This practical "hack" allows us to pinpoint only the variable quantity.  For example,
let's say that the volume of a box has two dimensions fixed at a and b feet, while
the third side is variable and represented by s.  We might encode this as:

--> V(s):=s*a*b;
\[\tag{%o17} \operatorname{V}(s):=s a b\]

To get the differential of V(s) relative only to s we compute:

--> dV:subst([del(a)=0,del(b)=0],diff(V(s)));
\[\tag{dV}a b \operatorname{del}(s)\]

Now we can compute the differential when, for instance, s=3 and del(s)=-0.01:

--> subst([del(s)=-0.01,s=3],dV);
\[\tag{%o20} -0.01 a b\]
--> kill(all);
\[\tag{%o0} \mathit{done}\]

 4 Related Rates

Suppose that we know that the radius of a cylinder is related to the height of the cylinder by way of: h(r)=(r^2+1)*cos(r):

--> h(r):=(r^2+1)*cos(r);
\[\tag{%o1} \operatorname{h}(r):=\left( {{r}^{2}}+1\right) \cos{(r)}\]

The volume of the cylinder is then:

--> V(r):=%pi*r^2*h(r);
\[\tag{%o2} \operatorname{V}(r):=\ensuremath{\pi} {{r}^{2}} \operatorname{h}(r)\]

We can then get the derivative of V(r) in the usual way:

--> diff(V(r),r);
\[\tag{%o3} -\ensuremath{\pi} {{r}^{2}}\, \left( {{r}^{2}}+1\right) \sin{(r)}+2 \ensuremath{\pi} {{r}^{3}} \cos{(r)}+2 \ensuremath{\pi} r\, \left( {{r}^{2}}+1\right) \cos{(r)}\]

But what if we *don't* know how h depends on r?  We know that there is a connection, but we aren't sure what it is?
Maxima can handle this too.  Let's clean up and start over:

--> kill(all);
\[\tag{%o0} \mathit{done}\]
--> V(r):=%pi*r^2*h(r);
\[\tag{%o1} \operatorname{V}(r):=\ensuremath{\pi} {{r}^{2}} \operatorname{h}(r)\]

Note that the above shows that h is a function of r, but we have not given it any explicit relationship yet.
Let's try differenting and see what happens:

--> diff(V(r),r);
\[\tag{%o2} \ensuremath{\pi} {{r}^{2}}\, \left( \frac{d}{d r} \operatorname{h}(r)\right) +2 \ensuremath{\pi} r \operatorname{h}(r)\]

Nice!  We see that Maxima treats the unknown function h(r) as a function and correctly applies the chain rule.
We can now substitute or solve for any of the above quantities just like we would in a related rates problem.
For example, suppose that we want to find dh/dr when h=2, r=3, and dV/dr=5:

First, we solve for dh/dr:

--> Eqn:solve(diff(V(r),r)=5,diff(h(r),r))[1];
\[\tag{Eqn}\frac{d}{d r} \operatorname{h}(r)=-\frac{2 \ensuremath{\pi} r \operatorname{h}(r)-5}{\ensuremath{\pi} {{r}^{2}}}\]

Now we substitute to get the numerical value required:

--> subst([h(r)=2,r=3],rhs(Eqn));
\[\tag{%o8} -\frac{12 \ensuremath{\pi} -5}{9 \ensuremath{\pi} }\]

Note that the order in which we substituted above matters.  Had we substituted r first
we would have arrived at:

--> subst([r=3,h(r)=2],rhs(Eqn));
\[\tag{%o9} -\frac{6 \ensuremath{\pi} \operatorname{h}(3)-5}{9 \ensuremath{\pi} }\]

Since substituting r=3 turns h(r) into h(3), and there is no longer an h(r) to substitute for!
We could get around this by noting that: h(3)=2 and so:

--> subst([r=3,h(3)=2],rhs(Eqn));
\[\tag{%o10} -\frac{12 \ensuremath{\pi} -5}{9 \ensuremath{\pi} }\]

Just for kicks, we note that:

--> is(-(12*%pi-5)/(9*%pi)<0);
\[\tag{%o13} \mbox{true}\]

so that the height is decreasing under these circumstances.


Created with wxMaxima.