In[49]:=

<<Graphics`

Calculus IV Lab 1: Limits and Functions

Limits

Taking a limit of a function of two variables can be very difficult.  Mathematica can take limits of a function of a single variable relatively easy:

Limit[Sin[x^(1/2)]/x, x0]

∞

However, it does not have a built-in command for finding the limit of a multi-variable function.  This is unfortunate (though not really surprising, considering the complications that can arise in 3 dimensions).  

For limits of functions of two variables, it can often be useful to graph the function around the limit point first.  This can give you an idea of whether the limit exists or not.  If it looks like it doesn't exist, the graph may give you some good ideas of what paths to test the limit along to look for differing values.  If you can find two different paths with two different limits, then you're done (the limit does not exist).  Mathematica can also aid you in taking limits along these paths.  If it looks like the limit does exist, you might be able to use Mathematica to ease your suffering as you try to prove it really does exist (sadly, Mathematica won't prove it for you...).

As an example, let's examine Underscript[Limit , (x, y)  (0, 0)] (x^3 + y^2)/(x^2 + y^2):

In[90]:=

Plot3D[(x^3 + y^2)/(x^2 + y^2), {x, -0.05, 0.05}, {y, -0.05, 0.05}, PlotPoints40]

[Graphics:HTMLFiles/index_7.gif]

Out[90]=

⁃SurfaceGraphics⁃

It can also be very useful to look at a contour plot over the same region:

In[91]:=

ContourPlot[(x^3 + y^2)/(x^2 + y^2), {x, -0.05, 0.05}, {y, -0.05, 0.05}, PlotPoints100]

[Graphics:HTMLFiles/index_10.gif]

Out[91]=

⁃ContourGraphics⁃

Although you can't really tell for certain here, it looks like the graph may approach different limits, depending upon what path you approach it on.  

Explain how the contour plot shows you the limit probably doesn't exist.

Now, let's test this on paths of the form y=m x:

In[92]:=

Limit[(x^3 + (m x)^2)/(x^2 + (m x)^2), x0]

Out[92]=

m^2/(1 + m^2)

A fancier way to do this would be using the "ReplaceAll" operator:

Limit[(x^3 + y^2)/(x^2 + y^2)/.ym x, x0]

m^2/(1 + m^2)

Since this depends upon m, the limit cannot exist.  On the other hand, consider Underscript[lim, (x, y)  (0, 0)](x y^2)/(x^2 + y^4):

In[93]:=

Plot3D[(x y^2)/(x^2 + y^4), {x, -0.5, 0.5}, {y, -0.5, 0.5}, PlotPoints100, MeshFalse]

[Graphics:HTMLFiles/index_19.gif]

Out[93]=

⁃SurfaceGraphics⁃

In[94]:=

ContourPlot[(x y^2)/(x^2 + y^4), {x, -0.2, 0.2}, {y, -0.2, 0.2}, PlotPoints100]

[Graphics:HTMLFiles/index_22.gif]

Out[94]=

⁃ContourGraphics⁃

The limit doesn't appear to exist here.  Again, let's check all linear paths through this point:

In[95]:=

Limit[(x  y^2)/(x^2 + y^4)/.ym x, x0]

Out[95]=

0

The contour lines here give you a clue:  they look (vaguely) parabolic.  So, let's try a parabolic path through the origin:

In[96]:=

Limit[(x  y^2)/(x^2 + y^4)/.ym x^2, x0]

Out[96]=

0

Of course, the contours actually look more like parabolas of the form x=m y^2:

In[97]:=

Limit[(x  y^2)/(x^2 + y^4)/.xm y^2, x0]

Out[97]=

m/(1 + m^2)

This goes to different limits for different values of m, so the original limit does not exist.  So, sometimes checking all lines isn't good enough.

Let's examine one more example:  Underscript[lim, (x, y)  (0, 0)]y^3/(x^2 + y^2)

In[98]:=

Plot3D[( y^3)/(x^2 + y^2), {x, -0.5, 0.5}, {y, -0.5, 0.5}, PlotPoints60, MeshFalse]

[Graphics:HTMLFiles/index_34.gif]

Out[98]=

⁃SurfaceGraphics⁃

In[99]:=

ContourPlot[( y^3)/(x^2 + y^2), {x, -0.5, 0.5}, {y, -0.5, 0.5}, PlotPoints100]

[Graphics:HTMLFiles/index_37.gif]

Out[99]=

⁃ContourGraphics⁃

Here, it looks like the limit DOES exist.  Notice that this doesn't actually prove this; you still have to figure out a way to do that.  Mathematica may or may not help to do this.  Hint:  for (x,y) close to (0,0), 0≤(y^3)/(x^2 + y^2)≤|y|

For each of the following, use Mathematica to decide whether the limit exists or not.  Support your decision with appropriate graphs.  If it doesn't exist, confirm this fact algebraically.

1.  Underscript[lim, (x, y)  (0, 0)] (tan(x^2y) cos(tan(x^2y)))/sin(tan(x^2y))

2.  Underscript[lim, (x, y)  (0, 0)]ln(x^2/y^6)/cos(x^3 - y^2)

Note:  Mathematica uses the function Log for the natural logarithm (rather than ln).

3.  Underscript[lim, (x, y)  (0, 0)]sin(3 y^2 + x)/tan(2 x^2 + y)

4.  Underscript[lim, (x, y)  (0, 0)](cos(2 x) ln(3 y^2))/(sin(6 x) tan(5 y))

5.  Underscript[lim, (x, y)  (0, 0)]^(x^2 - y^2)/(y^4 + ^x^4)

Functions

Composition of functions

There are different ways to define a function of more than one variable in Mathematica. For each of the following, give the dimension of the domain space and the dimension of the range space:

f[x_,y_,z_,t_]:=(x y z Sin[2π t])/(x^2 + y^2 + z^2)

g[x_,y_]:={y,x^2}

h[t_]:={Sin[t],Cos[t],t,2t}

Taking the composition of two functions is relatively easy (don't forget to evaluate the functions above first):

h[f[x, y, z, t]]

{Sin[(x y z Sin[2 π t])/(x^2 + y^2 + z^2)], Cos[(x y z Sin[2 π t])/(x^2 + y^2 + z^2)], (x y z Sin[2 π t])/(x^2 + y^2 + z^2), (2 x y z Sin[2 π t])/(x^2 + y^2 + z^2)}

However, try:

g[g[x, y]]

g[{y, x^2}]

This doesn't work.  It SHOULD work (Why?), but it doesn't. To get around this problem, we will often define functions of more than one variable in the following way:

g[{x_, y_}] := {y, x^2}

Now:

g[g[x, y]]

{x^2, y^2}

Will f[h[t]] work with the above definitions?  Should it?  If so, modify the definitions so it does.

Functions as arguments

Notice that if you have a function of a single variable, Mathematica knows what you mean by:

h '[t]

{Cos[t], -Sin[t], 1, 2}

Partial derivatives are also pretty straightforward:

∂_x g[x, y]

{0, 2 x}

Sometimes, it is useful to define a function that operates on other functions.  So, for example, I could define a function to find the derivative matrix for functions from ^2^2:

deriv2By2[expression_] := {∂_x expression, ∂_y expression}//Transpose//MatrixForm

deriv2By2[{x Sin[y], x Cos[y]}]

( {{Sin[y], x Cos[y]}, {Cos[y], -x Sin[y]}} )

deriv2By2[g[x, y]]

( {{0, 1}, {2 x, 0}} )

(Notice that I needed to transpose the matrix to get the rows/columns to work out like we want.  I used MatrixForm just because it looks cool.)  However, you have to be really careful with these.  For example, if I just make one minor little change when calling it:

deriv2By2[{u Cos[v], u Sin[v]}]

( {{0, 0}, {0, 0}} )

The problem is that, when we defined our function, we assumed that our variables would be called x and y, so any other choice of variables gets interpreted as a constant.  One way to fix this would be to explicitly specify your independent variables in the definition:

deriv2By2b[expression_, var1_, var2_] := {∂_var1 expression, ∂_var2 expression}//Transpose//MatrixForm

deriv2By2b[g[u, v], u, v]

( {{0, 1}, {2 u, 0}} )

This now works, though at the cost of a bit of redundancy in calling the function.  (There are fancier tricks we could use to generalize this, but this is a good starting point.)

If you need to access one of the components of a vector, you can use the notation:

g[x, y][[1]]

y

g[x, y][[2]]

x^2

Define your own functions to compute the gradient (call it myGrad), divergence (call it myDiv), and curl (call it myCurl) of an arbitrary function of 3 variables.  (You may not use any of the built-in functions that handle these.)  Demonstrate that each of these actually work for a few different functions.

ParametricPlot3D with spherical and cylindrical coordinates

Mathematica has special built-in functions for graphing cylindrical and polar coordinates (CylinderPlot3D and SphericalPlot3D).  Unfortunately, these aren't really as versatile as we might wish.  For example, they wouldn't be capable of plotting something as simple as φ=π/6.  Both of these commands are based on a much more flexible command, ParametricPlot3D.

ParametricPlot3D requires a function from either R^3 or ^2^3 as an input.  It will then graph the range of the function.  Thus:

In[88]:=

curve[t_] := {t, Sin[t], Cos[2t]}

In[89]:=

ParametricPlot3D[curve[t], {t, 0, 3π}]

[Graphics:HTMLFiles/index_85.gif]

Out[89]=

⁃Graphics3D⁃

This error message is harmless.  If it annoys you, you can get rid of it by the following:

In[100]:=

ParametricPlot3D[Evaluate[curve[t]], {t, 0, 3π}]

[Graphics:HTMLFiles/index_88.gif]

Out[100]=

⁃Graphics3D⁃

If you like, you can use ParametricPlot3D to draw a surface:

In[101]:=

surface[u_, v_] := {u Sin[v], u Cos[v], u^2}

In[102]:=

ParametricPlot3D[Evaluate[surface[u, v]], {u, -1, 1}, {v, 0, 2π}]

[Graphics:HTMLFiles/index_92.gif]

Out[102]=

⁃Graphics3D⁃

You can even use ParametricPlot3D to graph a function of 2 variables:

In[103]:=

f[x_, y_] := x^2 + y^2

In[104]:=

ParametricPlot3D[{x, y, f[x, y]}, {x, -1, 1}, {y, -1, 1}]

[Graphics:HTMLFiles/index_96.gif]

Out[104]=

⁃Graphics3D⁃

(If you had used the Plot3D function instead, it would have looked a little nicer...)

These two graphs look suspiciously alike.  Show that they are really the same surface.  Why do they look so different?

In order to use ParametricPlot3D to graph things in spherical and cylindrical coordinates, you must first develop a "change of variable" function. For example, a change of variable function for polar coordinates might look something like:

In[105]:=

polarToRect[{r_, θ_}] := {r Cos[θ], r Sin[θ]}

In[106]:=

rectToPolar[{x_, y_}] := {(x^2 + y^2)^(1/2), ArcTan[y/x]}

In[107]:=

polarToRect[{2, π/6}]

Out[107]=

{3^(1/2), 1}

In[108]:=

rectToPolar[{3^(1/2), 1}]

Out[108]=

{2, π/6}

In[109]:=

rectToPolar[polarToRect[{2, π/6}]]

Out[109]=

{2, π/6}

Warning:

In[110]:=

rectToPolar[{-3^(1/2), 1}]

Out[110]=

{2, -π/6}

What is wrong with this and why?

Fortunately, we are mainly interested in polarToRect (actually the equivalents for cylindrical and spherical coordinates).

Create 4 new functions: cylinderToRect (accepts points in the form {r,θ,z}), rectToCylinder, sphereToRect (accepts points in the form {ρ,θ,φ}), and rectToSphere to make the appropriate conversions.  Notice that all of these functions are from ^3^3.

You can use these new functions in conjunction with ParametricPlot3D to graph most equations in cylindrical and spherical coordinates. (You can even use it to graph cylindrical or spherical "parametric equations," something you don't see in many textbooks...)

For example, to graph something like ρ=Sin[θ]Cos[φ], you would do something like:

ρ = Sin[θ] Cos[ϕ]

ParametricPlot3D[sphereToRect[{ρ, θ, ϕ}], {θ, 0, 2π}, {ϕ, 0, 2π}]

(Notice that you can only have 2 independent variables inside ParametricPlot3D, θ and φ in this case.)

Of course, the built-in SphericalPlot3D function could have done this (with less effort). However, you can also use your new functions to plot θ=π/4:

ParametricPlot3D[sphereToRect[{ρ, π/4, ϕ}], {ρ, 0, 5}, {ϕ, 0, π}]

Use the functions you developed above to graph the following (carefully choose what regions to graph over):

1. r=z cos(2θ)

2. r z sec(θ)=1

3. φ=ρ sin(θ/2)

4. ρ^4sin^2(θ)=ϕ^3

5. ρ=2t, θ=sin(5t), φ=cos(7t)

6. r=sin(u)cos(v), θ=sin(u v), z=cos(u+v)


Created by Mathematica  (January 26, 2005) Valid XHTML 1.1!