Multivariate functions

> restart; with(plots):

Warning, the name changecoords has been redefined

> setoptions(scaling=constrained):
setoptions3d(axes=boxed,style=patchnogrid):

Here we look at the basics of multivariate functions (more than one independent variable).

Functions of two or three variables

Expressions

Create an expression with the names of the variables you want to use.

> f:= x^2*y;

f := x^2*y

> g:= u*v*sin(w);

g := u*v*sin(w)

Be careful: If one of your variables already has a value, you will not get what you expect.

> t:= Pi:

> h:= r*sqrt(s)/t;

h := r*s^(1/2)/Pi

> unassign('t');

> h:= r*sqrt(s)/t;

h := r*s^(1/2)/t

You can use eval to evaluate an expression at a particular point.

> eval( f, {x=2,y=3} );

12

> eval( h, {r=-1,s=9,t=3} );

-1/3*9^(1/2)

> simplify( % );

-1

Arrow functions (optional)

Arrow functions are an alternative to expressions.  They make some things much easier and other things harder.

Here is a multivariate function defined using arrows.

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

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

Evaluating f at a point is easy.

> f(2,3,5);

5*exp(-1)

Here is how to convert between arrow functions and expressions.

> f(x,y,z)

Warning, inserted missing semicolon at end of statement, f(x,y,z);

z*exp(x-y)

> unapply( z*exp(x-y), (x,y,z) );

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

Graphics

Two variables

In earlier 3D plots of quadric surfaces, we used implicitplot3d to plot a surface defined by an equation F(x,y,z)=0.  For a function of two variables, we can set z=f(x,y), and this can be plotted in the same way.  However, there is a special command for these plots called plot3d that is in some ways more convenient.

For example, if f(x, y) = xy^2 ,

> plot3d(x*y^2, x=-1..1,y=-2..2);

[Plot]

As usual, the right mouse button over the graphic (when in Maple) brings up a menu of options.

> plot3d(abs(x)+abs(y), x=-2..2,y=-2..2, style=patch );

[Plot]

> plot3d(sin(x)*cos(y), x=-2*Pi..2*Pi,y=-2*Pi..2*Pi, axes=boxed);

[Plot]

There is a contourplot function for plotting level curves.

> contourplot(abs(x)+abs(y), x=-2..2, y=-2..2);

[Plot]

The colors indicate the contour levels.  To see how contours relate to the surface, try

> contourplot3d( abs(x)+abs(y), x=-2..2, y=-2..2 );

[Plot]

By default, 8 contour levels are chosen automatically. You can give a different number, or specify the levels explicitly.

> contourplot(sin(x)*cos(y), x=-2*Pi..2*Pi,y=-2*Pi..2*Pi, contours=12);

[Plot]

Observe that contours tend to "surround" a local min or max.  You can specify the grid option to make the curves a little smoother.

> contourplot(sin(x)*cos(y), x=-2*Pi..2*Pi,y=-2*Pi..2*Pi, contours=[-1,-1/2,0,1/2,1], grid=[50, 50]);

[Plot]

Here are the contours of a saddle.

> contourplot(x^2-y^2, x=-1..1,y=-1..1, contours=13, grid=[51, 51]);

[Plot]

The signature of a saddle point is the crossing of contours.

Three variables

In this case a level surface is defined by f(x, y, z) = c , which is suitable for  implicitplot3d. For example, one level surface of the function sqrt(x^2+y^2+z^2) is

> implicitplot3d(sqrt(x^2+y^2+z^2)=1, x=-1..1,y=-1..1,z=-1..1, scaling=constrained);

[Plot]

The level surfaces of a linear function are planes:

> implicitplot3d(2*x+y-z=1, x=-2..2,y=-2..2,z=-2..2);

[Plot]

Level surfaces can be quite complicated.

> implicitplot3d(sin(x)*cos(y)*z=1/2, x=-Pi..Pi,y=-Pi..Pi,z=-2..2, grid=[19,19,19]);

[Plot]

Limits

Maple knows how to take some multidimensional limits.  

> limit( (x+y^2)/(2*x+y), {x=1,y=1} );

2/3

As in Calc I, the only touchy cases are indeterminate, such as 0/0.

> limit( (x^2-y^2)/(x+y), {x=0,y=0} );

0

This case was OK because the fraction was not in simplest form.

> normal( (x^2-y^2)/(x+y) );

x-y

Here is another case that Maple figures out.

> f:=  x^2/(x^2-y);

f := x^2/(x^2-y)

> limit( f, {x=0,y=0} );

undefined

In this case, Maple is clueless.

> f:= x*y/(x^2+y^2);

f := x*y/(x^2+y^2)

> limit( f, {x=0,y=0} );

limit(x*y/(x^2+y^2), {x = 0, y = 0})

A plot may reveal that something is fishy.

> plot3d( f, x=-1..1,y=-1..1, grid=[40,40]);

[Plot]

From this you can guess how to approach the origin along the surface along both high and low paths.

Analytically, you can try to evaluate the limit from different directions. If you ever get different answers, there is no limit. By "direction" we mean a curve in the xy plane that passes through the limiting point.  In the following example we use y=x and y=x^2.

> subs( y=x, f );

1/2

> subs( y=x^2, f );

x^3/(x^2+x^4)

> limit( %, x=0);

0

This proves that the limit does not exist.