Lesson #1: your calculator or computer may lie to you!

Univariate Calculus
Andy Long

Of course it’s not trying to be mean -- numerical instabilities can occur, that give the wrong answers -- which is why it’s so important to have an idea of what to expect.

(* Example #1, p. 51 *)
f[x_]:=(x-1)/(x^2-1)
(* What kind of function is f? *)
Plot[f[x],{x,-.5,2}]
(* What actually happens at x=1? *)
Limit[f[x],x -> 1]
(* From the left: *)
list={.5,.9,.99,.999,.9999}
 TableForm[Table[{x,f[x]},{x,list}]]
(* From the right: *)
list={1.5,1.1,1.01,1.001,1.0001}
 TableForm[Table[{x,f[x]},{x,list}]]

(* More lies your calculator tells you: *)
(* Example #2, p. 52 *)
f[x_]:=(Sqrt[x^2+9]-3)/x^2
Plot[f[x],{x,-.5,2}]
Limit[f[x],x -> 0]
(* From the left (or right: this function is symmetric): *)
list={1,.5,.1,.05,.01}
 TableForm[Table[{x,f[x]},{x,list}]]
(* We have to go a little further with Mathematica to "break" the function: *)
list={.0005,.0001,.00005,.00001,.000005,.000001,.0000005,.0000001}
 TableForm[Table[{x,f[x]},{x,list}]]
(* this next lie is that the function gets wild around x=0: *)
Plot[f[x],{x,-.00005,.00005}]

(* some functions aren't lying when they get wild: *)
(* Example #4, p. 53 *)
f[x_]:=Sin[Pi/x]
Plot[f[x],{x,-2,2}]
(* Notice what the "calculator" reports for a limit: *)
Limit[f[x],x -> 0]

(* Here's another lie Mathematica tells: *)
(* Example 6, p. 54 *)
Plot[HeavisideTheta[x],{x,-2,2}]
Limit[HeavisideTheta[x],x -> 0]
Limit[HeavisideTheta[x],x -> 0,
Direction->1]
Limit[HeavisideTheta[x],x -> 0,
Direction->-1]

(* Limits can be infinite (which gives rise to vertical asymptotes at a finite point):  *)
(* Example #9, p. 58 *)
f[x_]:=(2x)/(x-3)
Plot[f[x],{x,0,6}]
(* Note the lie *)
Limit[f[x],x -> 3]
(* as well as the truth: *)
(* From the left: *)
Limit[f[x],x -> 3,Direction->1]
(* From the right: *)
Limit[f[x],x -> 3,Direction->-1]