<< 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[(Sqrt[x])]/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 \(TraditionalForm\`\(\(Limit\)\(\ \)\)\+\(\((x, y)\) -> \((0, 0)\)\)\ \(x\^3 + \ y\^2\)\/\(x\^2 + y\^2\)\):

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

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

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

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:

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

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]

Since this depends upon m, the limit cannot exist.  On the other hand, consider \(TraditionalForm\`lim\+\(\((x, y)\) -> \((0, 0)\)\)\(x\ y\^2\)\/\(x\^2 + y\^4\)\):

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

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

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

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

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

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

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

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

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:  \(TraditionalForm\`lim\+\(\((x, y)\) -> \((0, 0)\)\)y\^3\/\(x\^2 + y\^2\)\)

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

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

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.  \(TraditionalForm\`lim\+\(\((x, y)\) -> \((0, 0)\)\)\ \(tan(\(x\^2\) y)\)\/\(sin(Tan(\(x\^2\) y))\)\)

2.  \(TraditionalForm\`lim\+\(\((x, y)\) -> \((0, 0)\)\)\(ln(x\^2 + y\^4)\)\/\(sin(x\^6 + y\^2)\)\)

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

3.  \(TraditionalForm\`lim\+\(\((x, y)\) -> \((0, 0)\)\)\(2  x - y\^2\)\/\(2  x\^2 + y\)\)

4.  \(TraditionalForm\`lim\+\(\((x, y)\) -> \((0, 0)\)\)\(\(cos(2  x)\) \(sin(3  y)\)\)\/\(\(sin(6  x)\) \(cos(5  y)\)\)\)

5.  \(TraditionalForm\`lim\+\(\((x, y)\) -> \((0, 0)\)\)\(x\^2 - y\^2\)\/\(x\^4 + y\^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, 
        2  t}

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

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

However, try:

g[g[x, y]]

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]]

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]

Partial derivatives are also pretty straightforward:

(∂_x) g[x, y]

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 \(TraditionalForm\`ℝ\^2 -> ℝ\^2\):

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

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

deriv2By2[g[x, y]]

(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]}]

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]

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]]

g[x, y][[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 \(TraditionalForm\`\(\(ℝ\)\(->\)\(ℝ\^3\)\(\ \)\)\)or \(TraditionalForm\`\(\(ℝ\^2\)\(->\)\(ℝ\^3\)\(\ \)\)\)as an input.  It will then graph the range of the function.  Thus:

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

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

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

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

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

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

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

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

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

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

(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:

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

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

polarToRect[{2, (π/6)}]

rectToPolar[{(Sqrt[3]), 1}]

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

Warning:

rectToPolar[{-(Sqrt[3]), 1}]

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 \(TraditionalForm\`ℝ\^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, π}]

(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, 
        2  π}]

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

1. r = z cos(θ)

2. r θ z = 1

3. ϕ = ρ sin(θ)

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

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

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