Mathematica Labs | Denis Shubleka

Subject: Calculus

Topic: Multivariable Functions

Goal: Use Mathematica to visualize functions in two variables.

Task 1

In Mathematica we define a real-valued function in two variables:

f[x_,y_]:=Cos[x]+Sin[y];

Or more conveniently:

Clear[f,x,y];
f=Cos[x]+Sin[y];

To evaluate the function at a given point (a, b), we use the replacement rules:

f/.{x->Pi/4,y->Pi/3}

Generally, if the answer needs simplification, use the Simplify command:

Simplify[%]

Note that the percentage sign refers to the result of the previous command.

Task 2

To sketch the domain of a function in two variables, we use the RegionPlot command. For example, the function:

f (x,y)=((Sqrt[x-(y^2)])/(y-x))

will exist whenever the denominator is nonzero and the expression inside th square root is greater than or equal to zero. We specify these inequalities in the Regionplot command:

RegionPlot[{x-(y^2)≥ 0,y-x ≠0},{x,-5,5},{y,-5,5},Axes->True]

Task 3

To plot a function of two variables in 3-space, we use the Plot3D command. Remember to include the bounds for each independent variable:

Plot3D[f,{x,-1,3},{y,-3,3}]

To get a vertical cross-section, we simply set one the independent variables equal to a specific value:

Plot[f/.y->Pi/3,{x,-1,3}]

Your turn: Set the x-coordinate to a specific value, to get a cross section of the surface that shows f(x,y) versus y.

Your turn: In the Documentation Center, look up the following options of Plot3D:PlotStyle, Lighting,PlotRange,BoxRatios,Boxed, and Axes. Explore at your own pace with a function of your own.

Task 4

To plot the level curves (contours) of a funtion of two variables, we use the ContourPlot command in Mathemaica. By default, it will produce ten contour regions separated by nine contour lines. The regions are shaded according to relative height in the z-direction. To set a custom number of contour lines, use the Contours property:

ContourPlot[x*y,{x,-3,3},{y,-3,3},Contours->20]

To plot level surfaces of functions in three variables (w = f(x, y, z)), we use the ContourPlot3D command. Here is an example:

ContourPlot3D[x^2+y^2+z^2,{x,-1,1},{y,-1,1},{z,0,1},BoxRatios->{2,2,1},Contours->5,Mesh->None]

Related Exercises/Notes:

1. Find and sketch the domains of the following functions by hand, and then use Mathematica’s RegionPlot command to confirm your answers.

f(x,y)=((ln(x+y))/(Sqrt[(x^2)+(y^2)-1]))
g(x,y)=((arcctan(x+y))/(Sqrt[(x^2)+(y^2)]))

2. Use the Plot3D command to graph the functions in the previous exercise. Visually confirm that the z-values only exist for pairs (x, y) in the domain you found earlier.

3. Use Mathematica to draw level curves (countour lines) for each function below. Describe in words the contours and how they are spaced.

h(x,y)=cos(Sqrt[(x^2)+(y^2)])


l(x,y)=(Sqrt[(x^2)+2(y^2)])

ap-calc.github.io