# Demonstrating the behavior of a function as its independent variable approaches zero

I have several questions regarding the function $$f(x)=\frac{\sqrt{x^2+9}-3}{x^2}$$ that I would like to help my students with in the upcoming semester.

Now, the limit as $x\to 0$ is 1/6.

Limit[f[x], x -> 0]

(* 1/6 *)


My first question regards approximating the limit as $x\to 0$ using a table.

Clear[f]
f[x_] := (Sqrt[x^2 + 9] - 3)/x^2; data =
Table[{N[10^(-n)], N[f[10^(-n)]]}, {n, 0, 8}];
Grid[Prepend[data, {"x", "f(x)"}],
Alignment -> Left,
Frame -> All]


Which gives the following table.

The point of this example is to show students that technology will sometimes get into a little trouble and might show information that leads students to assume an incorrect answer.

If I recall, the problem here is the fact that if you subtract two numbers that are really close to one another, you can quickly lose enough precision so that the numerator is interpreted as zero.

g[x_] := Sqrt[x^2 + 9] - 3;
Grid[Table[{N[10^(-n)], N[g[10^(-n)]]}, {n, 0, 8}],
Alignment -> Left,
Frame -> All]


Now, on a calculator, you are usually stuck as you cannot increase the precision. I think you can in Mathematica, but I've never tried it as yet. So, my first question is, how do I increase the Mathematica precision in these examples and increase the number of decimal places shown to demonstrate to the students what is going on here?

My second equation regards the graph of this equation. As you zoom in near zero, you begin to see some vibrations, maybe indicating that the limit does not exist.

Plot[f[t], {t, -10^(-6), 10^(-6)},
PlotRange -> {{-10^(-6), 10^(-6)}, {-0.1, 0.3}},
AxesLabel -> {"t", "y"}]


Again, can this particular image be improved by increasing the machine precision? How can I best explain this situation to the students?

Update: Consider the following image:

Clear[f]
f[x_] := (Sqrt[x^2 + 9] - 3)/x^2;
Plot[f[t], {t, -10^(-7), 10^(-7)},
PlotRange -> {{-10^(-7), 10^(-7)}, {-0.1, 0.3}},
AxesLabel -> {"t", "y"}]


What would be a good way to figure out exactly what points are being plotted here and why?

• With[{prec = 30}, Table[{N[10^(-n), prec], N[g[10^(-n)], prec]}, {n, 0, 8}]]. But you already knew about the second argument of N[], no? As for your plotting question, look up WorkingPrecision. – J. M. is in limbo Dec 12 '15 at 18:25
• For the plot look at the WorkingPrecision option – Simon Woods Dec 12 '15 at 18:40
• Also be careful of phrases like "increasing the machine precision" - machine precision is fixed by your computer's internal representation of floating point numbers. You can't increase it. A recommended read is the Background & Context section on this documentation page – Simon Woods Dec 12 '15 at 18:46
• If your students are at this point familiar with Taylor series then this would be a nice time to discuss "cancellation error". The series expansion shows that the first term in numerator behaves like 3 + x^2/6 - x^4/216. With evaluate around 10^(-8) and we expect, after subtraction of the second term (3), to have a residual slightly larger than 10^(-17), which means we have lost all significant digits if we are working with standard machine doubles (where an ULP is around 10^(-16)). – Daniel Lichtblau Dec 12 '15 at 21:57

Your function f is a good one for demonstrating to your students that they must be careful when working with a computer's built-in floating point capability. It is very fast, but because of its fixed and limited precision, it can never be absolutely trusted. Mathematica's is often to be preferred for serious numerics because you can switch from machine arithmetic to its built-in arbitrary precision arithmetic, where the precision can be increased at will, subject only to the constraints of available memory.

In you case, have your students compare the table you generated with machine arithmetic in your question with this one:

f[x_] := (Sqrt[x^2 + 9] - 3)/x^2;
data =
With[{precision = 20},
Table[{N[10^(-n)], N[f[10^(-n)], precision]}, {n, 0, 8}]];
Grid[Prepend[data, {"x", "f(x)"}], Alignment -> Left, Frame -> All]


I use a With expression to set the precision to make it easy to see what happens when the precision is varied. You might even convert the With expression into a Manipulate expression where the precision is set by a control.

You students can learn a lot from studying the limit behavior of f as x goes to zero. They can learn about limits and they can learn about how computer arithmetic works.

Mathematica's arbitrary precision arithmetic is, of course, much slower than the CPU's floating point arithmetic, but with this example you can show you students that, even in real life, the turtle can win the race because the rabbit gets lost and can't find the finish line.

• @m_goldberg All, I added an update to my question. What would be a good way of explaining what points are being plotted? – David Dec 13 '15 at 17:48
• @m_goldberg I added the function to your code and I also placed data= before the table. – David Dec 15 '15 at 1:22

Although this is a bit off topic as you are specifically interested in the approximation procedure, some of your students, if they are familiar with quadratic equations, might find out that they can find the limit purely algebraically.

Let

f = (Sqrt[x^2 + 9] - 3)/x^2


Observing that the denominator x^2 can be written as

(Sqrt[x^2 + 9] - 3)*(Sqrt[x^2 + 9] + 3) // Expand

(* Out[143]= x^2 *)


we can rewrite f as

f1 = (Sqrt[x^2 + 9] - 3)/((Sqrt[x^2 + 9] - 3)*(Sqrt[x^2 + 9] + 3));


Here the term (Sqrt[x^2 + 9] - 3) can be cancelled to give

f2 = 1/(Sqrt[x^2 + 9] + 3);


Now there is no problem letting x = 0 giving f = 1/6.