Review for test 2 in MTH 229

Test 2 will cover the 5th, 6th, and 7th projects: limits, derivatives, and the first and second derivatives. Some features we used are only available once the MTH229 package is loaded:

using MTH229
gr()
Plots.GRBackend()

Limits

We discussed three ways to investigate the answer (if it exists) to

$$~ \lim_{x \rightarrow c} f(x) ~$$$$~ f(t) = \frac{t - \sqrt{3t+4}}{4-t}, \text{ as } t \rightarrow 4 ~$$

Can be investigated by creating a graph around $c=4$:

f(t) = (t - sqrt(3t+4)) / (4-t)
plot(f, 3, 5)
Embedded Image

The answer looks to be about $-0.625$.

limit(f, 4)
-5/8

With this, making a table to investigate a limit is as easy as:

lim(f, 4, dir="+") ## going to 4 from right
6x2 Array{Float64,2}:
 4.1      -0.626742
 4.01     -0.625176
 4.001    -0.625018
 4.0001   -0.625002
 4.00001  -0.625   
 4.0      -0.625   

In this case, all three give the same answer – the limit is $-5/8 = -0.625$.

Other questions may include finding the distinction between left and right limits, limits of functions with jumps, or whether a limit can be found just by "plugging in".

Derivatives

We discussed three ways to find derivatives in Julia:

For example, for the function $f(x) = x - \log(x)$, we have the derivative at $2$ is approximately:

f(x) = x - log(x)
c = 2
h = 1e-6
(f(c+h) - f(c)) / h
0.5000001253030462

Different values of h lead to different answers. Mathematically, smaller h's are better but this isn't so once we use the computer, as too small values of h have issues with numeric round off.

With this notation, the above derivative is found with:

f'(c)
0.5

Second derivatives are found by using two primes:

f''(c)
0.25

The objects f' and f'' are just functions, so they can be used with our useful tools plot, fzero, lim, ...

diff(f)
1 - 1/x

At $c=2$, we can see this will also be $1/2$. These values are not functions. They do work with some tools, but not all.

First and second derivatives

A critical point is a value $x$ in the domain of $f$ where either the derivative of $f$ is 0 or it is undefined.

Information about first and second derivatives informs us about a function's behaviour. Roughly speaking: a positive derivative means a function is increasing, a postive second derivative means a function is concave up.

This helps us understand two "tests":

The first derivative test states that for a differentiable function $f(x)$ with a critical point at $c$ then if $f′(x)$ changes sign from + to − at c then $f(c)$ is a local maximum and if it changes sign from − to + then $f(c)$ is a local minimum

The second derivative test states that if $c$ is a critical point of $f(x)$ and $f″(c)>0$ then $f(c)$ is a local minimum and if $f″(c)<0$ then $f(c)$ is a local maximum.

Where a critical point is a value in the domain of $f(x)$ where the derivative is $0$ or undefined. In contrast, an inflection point is a point where $f''(x)$ is $0$ or undefined and the second derivative changes sign at this point.

To find these we used fzero and fzeros. The function fzero(f, a, b) will find a zero of $f(x)$ within a bracketing interval $[a,b]$. The function fzeros(f, a, b) will try to find the zeros of $f$ between $[a,b]$. (It may miss zeros that do not cross the $x$ axis!)

For example, if $f(x) = \cos(x) - \log(x)$ on $(0,10)$ we have the critical points found with:

f(x) = cos(x) - log(x)
cps = fzeros(f', 0, 10)
3-element Array{Float64,1}:
 3.43683
 6.11902
 9.5299 

(The function is differentiable on this interval, so there are no critical points corresponding to undefined derivatives.)

Can we use the second derivative test to classify these critical points as relative maxima or minima? We need to evaluate $f''(x)$ at the three values, a task made easy with this command (though you could type in the 3 values as f''(3.43683), ...)

map(f'', cps)
3-element Array{Float64,1}:
  1.04139 
 -0.959848
  1.00549 

If the second derivative is positive – its a relative min, if the second derivative is negative – its a relative max. So $3.43683$ has a relative minimum, $6.11902$ a relative maximum, and $9.5299$ a relative min.

The first derivative test looks at the change of sign of the derivative at the critical points. In the graph below we see that at each critical point $f'$ is zero:

plot(f', 3, 10)
Embedded Image

At $3.43683$ the derivative changes sign negative to positive, which says $f$ has a relative minimum there – in agreement with the second derivative test. Ditto for the critical point at $9.5299$. The critical $6.11902$ has the derivitave change sign from positive to negative, so the critical point will correspond to a relative maximum – again, what we also saw with the second derivative test.


The inflection points are found by considering this output

fzeros(f'', 0, 10)
2-element Array{Float64,1}:
 4.7566
 7.8377

These may not be inflection points, as we also need a change in concavity which must be checked for. In this case, we see that $f''$ changes sign using the graph:

plot(f'', 4, 8)
Embedded Image

The plotif function from the MTH229 package was helpful in graphical explorations.

Helpful functions

The MTH229 function provides functions secant and tangent to produce functions that describe a secant line or tangent line. Here we see both on the same graph. Can you tell which is tangent?

f(x) = sin(x)
c = pi/4
h = pi/8
a, b = 0, pi/2
plot(f, a, b)
plot!(secant(f, c, c+h), a, b)
plot!(tangent(f, c), a, b)
Embedded Image