Differentials

Last-modified: 2025-03-16 (日) 20:54:25

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);
    2xdel(x)(%o1)
    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);
    (3s2+2)del(s)(%o2)
    If we had defined a function f(x) first, then:
  • > f(x):=cos(x);
    diff(f(x));
    f(x):=cos(x)(%o3)
    -sin(x)del(x)(%o4)
    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);
    2xdel(x)(df)
  • > subst([del(x)=0.1,x=1],df);
    0.2(%o6)
    That's it! Or in one line:
  • > subst([del(x)=0.1,x=1],diff(x^2));
    0.2(%o7)
    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));
    2del(1)(%o8)
    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;
    V(r):=πr2h(%o9)
    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));
    2πhrdel(r)+πr2del(h)(%o10)
    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)));
    2πhrdel(r)(%o16)
    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;
    V(s):=sab(%o17)
    To get the differential of V(s) relative only to s we compute:
  • > dV:subst([del(a)=0,del(b)=0],diff(V(s)));
    abdel(s)(dV)
    Now we can compute the differential when, for instance, s=3 and del(s)=-0.01:
  • > subst([del(s)=-0.01,s=3],dV);
    -0.01ab(%o20)
  • > kill(all);
    done(%o0)
    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);
    h(r):=(r2+1)cos(r)(%o1)
    The volume of the cylinder is then:
  • > V(r):=%pi*r^2*h(r);
    V(r):=πr2h(r)(%o2)
    We can then get the derivative of V(r) in the usual way:
  • > diff(V(r),r);
    -πr2(r2+1)sin(r)+2πr3cos(r)+2πr(r2+1)cos(r)(%o3)
    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);
    done(%o0)
  • > V(r):=%pi*r^2*h(r);
    V(r):=πr2h(r)(%o1)
    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);
    πr2(ddrh(r))+2πrh(r)(%o2)
    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];
    ddrh(r)=-2πrh(r)-5πr2(Eqn)
    Now we substitute to get the numerical value required:
  • > subst([h(r)=2,r=3],rhs(Eqn));
    -12π-59π(%o8)
    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));
    -6πh(3)-59π(%o9)
    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));
    -12π-59π(%o10)
    Just for kicks, we note that:
  • > is(-(12*%pi-5)/(9*%pi)<0);
    true(%o13)
    so that the height is decreasing under these circumstances.