Partial derivatives and linearization

> restart;

In this worksheet we look at the fundamentals of using partial derivatives in Maple.

Basics

The commands for partial derivatives look exactly the same as for ordinary derivatives. Use diff.

> diff( sin(x)*cos(y), x );

cos(x)*cos(y)

From the definition (not to be used in everyday work),

> limit( (sin(x+h)*cos(y) - sin(x)*cos(y)) / h, h=0 );

cos(x)*cos(y)

The other first partial:

> diff( sin(x)*cos(y), y );

-sin(x)*sin(y)

For an unknown or "generic" function:

> diff( g(x,y,z), z );

diff(g(x, y, z), z)

It was important above to say which variables g depends on.  Compare to

> diff( g, z );

0

To take higher-order derivatives, specify more of the independent variables.

> diff( x^3*y^2, x );

3*x^2*y^2

> diff( x^3*y^2, x,x );

6*x*y^2

> diff( x^3*y^2, x,y );

6*x^2*y

> diff( g(x,y), x,y,x );

diff(g(x, y), `$`(x, 2), y)

Maple assumes the order of derivatives may be changed freely (as is always the case for the functions we'll encounter).

If you want the derivative at the point (1,2,3), you must differentiate before evaluation.

> f:= x*y^2*z^3:

> pt:= {x=-1,y=2,z=-3}:

WRONG:

> diff( eval(f,pt), z );

0

RIGHT:

> eval( diff(f,z), pt );

-108

Implicit differentiation

Let's use the Law of Cosines.  In a triangle with side lengths a, b, c, the angle A opposite side a satisfies

> LC:=  a^2 = b^2 + c^2 - 2*b*c*cos( A );

LC := a^2 = b^2+c^2-2*b*c*cos(A)

This is the syntax for finding Diff(A, b)

> implicitdiff( LC, A, b );

-(b-c*cos(A))/(b*c*sin(A))

Here is how you would find Diff(c, a)

> implicitdiff( LC, c, a );

-a/(-c+b*cos(A))

Ideal gas law examples:

> implicitdiff( P*V=R*T, P, T);

R/V

> implicitdiff( P*V=R*T, V, P);

-V/P

Functional form (optional)

If you define an arrow function using ->, then you differentiate using D.  Since the variable names are irrelevant to an arrow function, you refer to them by number.

> f:= (x,y,z) -> exp(x-y)*sin(x*z);

f := proc (x, y, z) options operator, arrow; exp(x-y)*sin(x*z) end proc

> D[1](f);

proc (x, y, z) options operator, arrow; exp(x-y)*sin(x*z)+exp(x-y)*cos(x*z)*z end proc

The result above is the same as

> diff( f(x,y,z), x );

exp(x-y)*sin(x*z)+exp(x-y)*cos(x*z)*z

> D[2](f);

proc (x, y, z) options operator, arrow; -exp(x-y)*sin(x*z) end proc

> D[1](%);

proc (x, y, z) options operator, arrow; -exp(x-y)*sin(x*z)-exp(x-y)*cos(x*z)*z end proc

> D[2,1](f);

proc (x, y, z) options operator, arrow; -exp(x-y)*sin(x*z)-exp(x-y)*cos(x*z)*z end proc

One of the main advantages of this form is in evaluating at a point.

> D[1](f)(2,3,Pi);

exp(-1)*Pi

Chain rule

Maple automatically applies the chain rule.  For instance, if x and y both depend on s and t,

> z:= exp(x(s,t))*sin(y(s,t));

z := exp(x(s, t))*sin(y(s, t))

> diff(z,s);

diff(x(s, t), s)*exp(x(s, t))*sin(y(s, t))+exp(x(s, t))*cos(y(s, t))*diff(y(s, t), s)

> eval( %, {x(s,t)=s*t,y(s,t)=s^3*t^2} );

t*exp(s*t)*sin(s^3*t^2)+3*exp(s*t)*cos(s^3*t^2)*s^2*t^2

Linearization

Let's compute the linearization of 4-x^2-2*y^2 at the point (0,1).

> f:= 4 - x^2 - 2*y^2:

> pt:= { x=0, y=1 }:

> fx:= diff( f, x );

fx := -2*x

> fy:= diff( f, y );

fy := -4*y

> eval( fx, pt );  eval( fy, pt );

0

-4

This is the textbook definition for the linearization.

> L:= eval(f,pt) + (x-0)*eval(fx,pt) + (y-1)*eval(fy,pt);

L := 6-4*y

In fact, z=L(x,y) is just the equation for a plane.

> plot3d( L, x=0..2,y=1..3, axes=boxed );

If we plot f and L together, we get a good idea of the quality of the approximation.

> plot3d( {f,L}, x=-0.5..0.5,y=0.5..1.5, axes=boxed );

[Plot]

By turning the graph in Maple you can see that the linearization is very good near the center point, but less so as you get farther away.

The main use for linearization is in approximation and estimation. It gives a good idea how f responds when the variable values are changed a little bit. Put another way, if the variable values are uncertain (and nothing in this world is certain), then f could potentially have a range of values. Linearization gives us an idea of that range.

The example of a new generation

A can of Pepsi could be modeled as a cylinder of radius r=1 inch and height h=5 inches. The factory foreman says that they can produce cans to within a tolerance of 1% in both dimensions. What effect could this have on the volume of the can?

The volume is

> V:= Pi*r^2*h;

V := Pi*r^2*h

We find the partial derivatives needed for the linearization.

> Vr:= diff( V, r );

Vr := 2*Pi*r*h

> Vh:= diff( V, h );

Vh := Pi*r^2

The linearization in differential form is

> dV:= Vr*dr + Vh*dh;

dV := 2*Pi*r*h*dr+Pi*r^2*dh

We know that dr can be as large as 0.01*r and dh can be 0.01*h.

> dV:= eval( dV, {dr=r/100, dh=h/100 } );

dV := 3/100*Pi*r^2*h

Evaluate this for the original can.

> can:= { r=1, h=5 }:

> eval( dV, can );

3/20*Pi

> evalf( % );

.4712388981

This answer is in cubic inches.

Up-chucking

A woodchuck wants to chuck a box made of wood 1/2-inch thick with inside dimensions 5 ft x 3 ft x 2 ft. The box has no top. How much wood would the woodchuck chuck?

The volume of wood is the volume of the outside of the box minus the volume of the inside.  The inside volume is given by

> V:= l*w*h;

V := l*w*h

To get to the outside of the box, we increase each dimension by 1/2 inch. This changes l and w by 1 inch total but h by only 1/2 an inch (because the top is missing). The resulting change in volume is about

> dVdl:= diff(V,l);

dVdl := w*h

> dVdw:= diff(V,w);

dVdw := l*h

> dVdh:= diff(V,h);

dVdh := l*w

> dV:= dVdl*(1) + dVdw*(1) + dVdh*(1/2);

dV := w*h+l*h+1/2*l*w

> box:= { l=60, w=36, h=24 }:

> eval( dV, box );

3384

This is in cubic inches.