To get started, we load the MTH229
package so that we can make plots and use some symbolic math:
using MTH229
using Plots
plotly()
┌ Info: For saving to png with the Plotly backend PlotlyBase has to be installed. └ @ Plots /Users/verzani/.julia/packages/Plots/1KWPG/src/backends.jl:318
Plots.PlotlyBackend()
Read about this material here: Investigating limits with Julia.
For the impatient, the expression
says that the limit as $x$ goes to $c$ of $f$ is $L$.
Intuitively, as $x$ gets "close" to $c$, $f(x)$ should be close to $L$.
If $f(x)$ is continuous at $x=c$, then $L=f(c)$. This is almost always the case for a randomly chosen $c$ - but almost never the case for a textbook choice of $c$. Invariably with text book examples–-though not always–-we will have f(c) = NaN
indicating the function is indeterminate at c
. For such cases we need to do more work to identify if any such $L$ exists and when it does, what its value is.
In this project, we investigate limits three ways: graphically, with a table of numbers, and analytically, developing the inituition of limits along the way.
The graphical approach is to plot the expression near $c$ and look visually what $f(x)$ goes to as $x$ gets close to $c$.
For example, what is this limit?
Here is a graph to investigate the problem. We simply graph near $c$ and look:
f(x) = (1-sin(x)) / (pi/2 - x)^2
c = pi/2
plot(f, c - pi/6, c + pi/6)
From the graph, we see clearly that as $x$ is close to $c=\pi/2$, $f(x)$ is close to $1/2$. (The fact that f(pi/2) = NaN
will either not come up, as pi/2
is not among the points sampled or the NaN
values will not be plotted.)
Investigating a limit numerically requires us to operationalize the idea of $x$ getting close to $c$ and $f(x)$ getting close to $L$. Here we do this manually:
f(x) = sin(x)/x
f(0.1), f(0.01), f(0.001), f(0.0001), f(0.00001), f(0.000001)
(0.9983341664682815, 0.9999833334166665, 0.9999998333333416, 0.9999999983333334, 0.9999999999833332, 0.9999999999998334)
From this we see a right limit at 0 appears to be $1$.
We can put the above into a column, by wrapping things in square brackets (forming a vector):
[f(0.1), f(0.01), f(0.001), f(0.0001), f(0.00001), f(0.000001)]
6-element Vector{Float64}: 0.9983341664682815 0.9999833334166665 0.9999998333333416 0.9999999983333334 0.9999999999833332 0.9999999999998334
The style of printing makes it clear, the limit here should be $L=1$.
Limits when $c\neq 0$ are similar, but require points getting close to $c$. For example,
has a limit of $1/2$. We can investigate with:
c = pi/2
f(x) = (1 - sin(x))/(pi/2 - x)^2
[f(c+.1), f(c+.001), f(c+.00001), f(c+.0000001), f(c+.000000001)]
5-element Vector{Float64}: 0.49958347219742816 0.4999999583256134 0.5000000413636343 0.49960036049791995 0.0
Wait, is the limit $1/2$ or $0$? At first $1/2$ seems like the answer, but the last number is $0$.
Here we see a limitation of tables - when numbers get too small, that fact that they are represented in floating point becomes important. In this case, for numbers too close to $\pi/2$ the value on the computer for sin(x)
is just 1 and not a number near 1. Hence the denominator becomes $0$, and so then the expression. (Near $1$, the floating point values are about $10^{-16}$ apart, so when two numbers are within $10^{-16}$ of each other, they can be rounded to the same number.) So watch out when seeing what the values of $f(x)$ get close to. Here it is clear that the limit is heading towards $0.5$ until we get too close.
For convenience, the lim
function from the MTH229
package can make the above computations easier to do. Its use follows the common pattern: action(function, arguments...)
. For example,
f(x) = (1 - sin(x))/(pi/2 - x)^2
lim(f, pi/2)
6×2 Matrix{Float64}: 1.6708 0.499583 1.5808 0.499996 1.5718 0.5 1.5709 0.5 1.57081 0.5 1.5708 0.500044
The above will generate values just bigger than pi/2
which are helpful to investigate the right limit. For a left limit, pass in dir="-"
, as with
lim(f, pi/2, dir="-")
6×2 Matrix{Float64}: 1.4708 0.499583 1.5608 0.499996 1.5698 0.5 1.5707 0.5 1.57079 0.5 1.5708 0.500044
The add-on package SymPy
can be used to analytically compute the limit of a symbolic expressino. The package is loaded when MTH229
is. SymPy
provides the limit
function. A sample usage is shown below:
f(x) = sin(x)/x
@syms x
limit(f(x), x => 0)
The new command, @syms x
, creates a symbolic variable named x
. This makes f(x)
a symbolic expression
f(x)
To find the limit of an expression, ex
, as a symbolic variable, x
, goes towards some value c
, 0
in the above example, is performed by the command limit(ex, x => c)
. SymPy finds the right limit by default. A left limit can be asked for with the additional argument dir="-"
.