Taking a limit depends on the path used to approach that limit.
Consider the function in the question:
f[x_, y_] := Piecewise[{{x y / (x^2 + y^2), x != 0 && y != 0}}, 0];
base = Plot3D[f[x, y], {x, -1, 1}, {y, -1, 1}, MeshStyle->Opacity[0.2], PlotStyle->Opacity[0.5]]
(A plot of its graph, saved here as base
, appears in subsequent figures.)
For instance, we may approach the origin along any ray given by a nonzero vector $(u,v)$; such rays can be parameterized by $t \to t(u,v)$:
c[t_, {u_, v_}] := t {u, v}
The value $t=0$ corresponds to the origin. To find the limit, we need to "lift" the approach path up to the "elevations" determined by $f$. When the original path is parameterized as $(x(t), y(t))$, then the lift is parameterized by $\left(x(t), y(t), f(x(t), y(t))\right)$:
lift[t_, f_, c_, opts___] := With[{x = c[t, opts]}, Append[x, f @@ x]]
(In this definition I have provided a mechanism to pass the ray vector $(u,v)$ as an option to lift
.) Let's graph some of these lifts for various rays, using (of course) ParametricPlot3D
:
trailRays = ParametricPlot3D[Evaluate@lift[t, f, c, #], {t, -1, 1},
PlotStyle -> Thickness[0.01], ColorFunction -> Function[{x, y, z, u}, Hue[u]]] & /@
{{1, 0}, {1,1}, {1, -2}};
Show[base, trailRays, Boxed -> False]
Especially when you can manipulate this plot in Mathematica, it is evident how the lifts of the various curves approach different limiting elevations at the origin.
Here is a more interesting way to approach the origin: spiral in. This time the value $t=\infty$ corresponds to the limit at the origin:
b[t_] := {Cos[t], Sin[t]} /Sqrt[t]
Let's plot (part of) its lift:
trail = ParametricPlot3D[Evaluate@lift[t, f, b], {t, 1, 30},
PlotStyle -> Thickness[0.01], ColorFunction -> Function[{x, y, z, u}, Hue[u]]];
Show[base, trail, Boxed -> False]
As we spiral in toward the origin, the lift swoops up and down as the curve passes back and forth past all the incoming rays infinitely many times, never approaching a definite limit. This is a partial plot of the elevation as a function of the parameter $t$ along the curve; the graduated hues match those of the preceding plot:
Plot[f @@ b[t], {t, 0, 30}, PlotStyle -> Thick, AxesLabel -> {t, f}, ColorFunction -> (Hue[#1] &)]
(Analogous plots along the rays would be uninteresting, because along any ray through the origin, the value of $f$ does not vary at all!)
We may confirm visual impressions by applying Limit
. The whole point is that the limit is taken along a curve, so it involves only a single (real) variable. Using the work we have already done, this is easy. Thus:
Limit[f @@ c[t, {u, v}], t -> 0]
$\begin{array}{ll}
\{ &
\begin{array}{ll}
\frac{u v}{u^2+v^2} & (\text{Im}[u]\neq 0\|\text{Re}[u]\neq 0)\&\&(\text{Im}[v]\neq 0\|\text{Re}[v]\neq 0) \\
0 & \text{True}
\end{array}
\end{array}$
There is a definite limit along each ray whose value is given here in terms of the ray vector's coordinates $(u,v)$. How about approaching the origin along the spiraling curve $b$?
Limit[f @@ b[t], t -> Infinity] // FullSimplify
Mathematica evaluates and simplifies f @@ b[t]
, but otherwise it--correctly--cannot obtain any limit and so just spits out another Limit
expression.
Note that to study limits in more than one dimension, it does not suffice to study limits along rays (or lines) only. One can construct "nastier" functions f
which have no definite limit when the origin is approached along a line, but do have definite limits when approached along particular spirals (or other curves of your choice). For instance, take our spiraling path $b$. At every point $(x,y)$ not at the origin we may locate two "arms" of the spiral, a nearest one and a next-nearest one, at distances $d_0$ and $d_1$, respectively. Let $f(x,y)$ be $d_0^2/d_1^3$. Because these distance functions are continuous and $d_1$ is never zero, $f$ is continuous. At all points equidistant between two arms (and there are many of these spiraling into the origin), $d_0=d_1$ and so $f = 1/d_1$, which clearly grows unbounded as the origin is approached. Any ray into the origin will hit infinitely many such points. But if we stick along one of the original arms of the spiral, $d_0$ is constantly $0$ and so, therefore, is $f$, whence its limiting value along that arm is $0$.
Illustrating this are plots of $r^2 g(r, \theta)$ and $g(r, \theta)$ for the function $g = 4t(1-t)$ (defined in polar coordinates $(r,\theta)$) where $t =\mod(\frac{1}{r} - \frac{\theta}{2\pi})$ has a fairly innocent definition that nevertheless reproduces the qualitative structure of the preceding description, including the lack of any limits at the origin along rays. The left plot lowers the values of $g$ near the origin so we can see the structure; the right one shows the spiraling "fences" created by the graph of $g$. Underneath each plot is show (in black) the locus of points where $g=0$: the limiting value of $g$ at $(0,0)$ along this curve clearly is zero.
Limit
, you're always restricted to a line in the larger space, and you can't make statements about the existence of the limit in the sense of the higher-dimensional space. For that, you have to show the independence of the result on the direction of the line. If you intentionally set up a function to have different limits along different lines, I don't see what else you can do with Mathematica. $\endgroup$