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; |
| > | 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; |
| > | unassign('t'); |
| > | h:= r*sqrt(s)/t; |
You can use eval to evaluate an expression at a particular point.
| > | eval( f, {x=2,y=3} ); |
| > | eval( h, {r=-1,s=9,t=3} ); |
| > | simplify( % ); |
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); |
Evaluating f at a point is easy.
| > | f(2,3,5); |
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);
| > | unapply( z*exp(x-y), (x,y,z) ); |
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
,
| > | plot3d(x*y^2, x=-1..1,y=-2..2); |
![[Plot]](images/MultivariateFunctions_17.gif)
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]](images/MultivariateFunctions_18.gif)
| > | plot3d(sin(x)*cos(y), x=-2*Pi..2*Pi,y=-2*Pi..2*Pi, axes=boxed); |
![[Plot]](images/MultivariateFunctions_19.gif)
There is a contourplot function for plotting level curves.
| > | contourplot(abs(x)+abs(y), x=-2..2, y=-2..2); |
![[Plot]](images/MultivariateFunctions_20.gif)
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]](images/MultivariateFunctions_21.gif)
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]](images/MultivariateFunctions_22.gif)
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]](images/MultivariateFunctions_23.gif)
Here are the contours of a saddle.
| > | contourplot(x^2-y^2, x=-1..1,y=-1..1, contours=13, grid=[51, 51]); |
![[Plot]](images/MultivariateFunctions_24.gif)
The signature of a saddle point is the crossing of contours.
Three variables
In this case a level surface is defined by
, which is suitable for implicitplot3d. For example, one level surface of the function
is
| > | implicitplot3d(sqrt(x^2+y^2+z^2)=1, x=-1..1,y=-1..1,z=-1..1, scaling=constrained); |
![[Plot]](images/MultivariateFunctions_27.gif)
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]](images/MultivariateFunctions_28.gif)
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]](images/MultivariateFunctions_29.gif)
Limits
Maple knows how to take some multidimensional limits.
| > | limit( (x+y^2)/(2*x+y), {x=1,y=1} ); |
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} ); |
This case was OK because the fraction was not in simplest form.
| > | normal( (x^2-y^2)/(x+y) ); |
Here is another case that Maple figures out.
| > | f:= x^2/(x^2-y); |
| > | limit( f, {x=0,y=0} ); |
In this case, Maple is clueless.
| > | f:= x*y/(x^2+y^2); |
| > | limit( f, {x=0,y=0} ); |
A plot may reveal that something is fishy.
| > | plot3d( f, x=-1..1,y=-1..1, grid=[40,40]); |
![[Plot]](images/MultivariateFunctions_37.gif)
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 ); |
| > | subs( y=x^2, f ); |
| > | limit( %, x=0); |
This proves that the limit does not exist.