It is often convenient to approximate a complicated function using a simpler function. The "simpler" function is often a polynomial. The simplest polynomial is a straight line (degree 1). Approximating a function with a linear function is called linearization (or linear approximation). Approximating a function with a degree 2 polynomial (a parabola) is called quadratic approximation. We will discuss these two approximation methods today, and we'll save approximation with higher degree polynomials for Calculus 2.
Of course, it's kind of silly to do linear or quadratic approximation with the computer, since the computer can do much more accurate approximations of these functions. The point of this lab is to see just how accurate these simple approximations can be.
As we have seen several times this semester, differentiable functions are "close to" their tangent lines near the point of tangency. This means that we can approximate any differentiable function with a tangent line (at least over a small interval).
Let's start with a relatively simple example.
Suppose we want to approximate $\sqrt[3]{28}$ without a computer or calculator. The cube root function is complicated (at least by hand), so we'll approximate the cube root with a simple linear function, a tangent line.
What point of tangency do we choose? There are two requirements:
The x-coordinate needs to be close to 28, since our approximation only works close to the point of tangency.
It needs to be simple to compute the function value at this x-coordinate (this is the y-coordinate of the point of tangency, and we don't want to approximate this).
For this example, we will choose the tangent line at $x=27$. This value is fairly close to 28, and it is easy to compute $\sqrt[3]{27}=3$ (27 is a perfect cube).
Now let's compute the tangent line and use this line to approximate $\sqrt[3]{28}$.
First, define the function we're trying to approximate:
Find the derivative:
Now we need to find $f'(27)$ to get the slope of the tangent line. If $f(27)$ is simple to compute, then $f'(27)$ is probably simple to compute as well.
In this case, $\displaystyle f'(x)=\frac{1}{3x^{2/3}}$, so $\displaystyle f'(27)=\frac{1}{3\cdot27^{2/3}}=\frac{1}{3\cdot3^2}=\frac{1}{27}$.
Find an equation for the tangent line: $TL(x)=f(x_0)+f'(x_0)(x-x_0)$
Just to check our work, let's graph $f$ and $TL$ near $x=27$. [Of course, if we were actually doing approximation by hand, we wouldn't do this step.]
As we expected, the tangent line is close to the graph of $f$ near $x=27$.
Now let's use the tangent line to approximate $\sqrt[3]{28}$.
The tangent line has equation $TL(x)=3+\frac{1}{27}(x-27)$. Since $\sqrt[3]{x}\approx TL(x)$ (near $x=27$), we have $\sqrt[3]{28}\approx TL(28)=3+\frac{1}{27}(28-27)=3+\frac{1}{27}=\frac{82}{27}\approx3.0370$.
Compare this to Sage's approximation of $\sqrt[3]{28}$:
Our approximation is off by about $3.03703703703704-3.03658897187566=0.000448065161379851$, for a percent error of around $0.0148\%$.
Suppose we would like to find $\displaystyle\sqrt[3]{29}$ as well?
Since 29 is still fairly close to 27, we can use the same tangent line to get a linear approximation:
$\sqrt[3]{29}\approx TL(29)=3+\frac{1}{27}(29-27)=3+\frac{2}{27}=\frac{83}{27}\approx3.0741$.
Sage gives us $\sqrt[3]{29}\approx 3.0723$.
This gives a percent error of about $0.0572\%$
This linear approximation is only good when $x$ is close to 27.
Here is a graph of the percent error versus $x$. You can see that the error increases as you move away from 27.
Even 7 units away from 27 (in either direction), the error is less than 1%. Not bad for an approximation that you could easily do on a napkin over lunch!
Now let's use linear approximation to estimate $\sin\left(\frac{\pi}{5}\right)$. This is not one of the exact values we learned in precalc, but $\frac{\pi}{5}$ is not too far from $\frac{\pi}{6}$, and we recall from precalc that $\sin\left(\frac{\pi}{6}\right)=\frac{1}{2}$. So we'll use $\left(\frac{\pi}{6},\frac{1}{2}\right)$ as our point of tangency.
For this example, we'll let Sage do all the work, but it could be done by hand without too much trouble.
Our approximation is off by about $0.5\%$.
To check our work, here's a graph of $f$ and $TL$ near $x=\frac{\pi}{6}$.
Here's a graph of the percent error. You can see that it's much worse than our cube root example above.
Just out of curiosity, would would happen if we chose the tangent line at $x=\frac{\pi}{4}$? This is close to $\frac{\pi}{5}$ and we know the exact value of $\sin\left(\frac{\pi}{4}\right)$ as well.
I'll just cut and paste the input from above. The only thing I need to change is x_tangent.
Now I'm off by about $1.4\%$. This is not surprising, since $\frac{\pi}{4}\approx0.785$ is further away from $\frac{\pi}{5}\approx0.628$ than $\frac{\pi}{6}\approx0.524$.
Suppose we have a function $f(x)$ and its tangent line $TL(x)$ at the point $(x_0,f(x_0))$.
Recall, an equation of the tangent line is $TL(x)=f(x_0)+f'(x_0)(x-x_0)$. The derivative of $TL$ is the constant $f'(x_0)$ (the derivative of a linear function is a constant, equal to its slope). In other words, at the point $(x_0,f(x_0))$, the functions $f$ and $TL$ have the same derivative (or slope). [The point of the tangent line in the first place was to find the slope of $f$ at the point of tangency.] A linear function is completely determined by two pieces of information, in this case (1) the point of tangency, and (2) the slope.
To do quadratic approximation, we want to find a "tangent parabola" for our function $f$ at the point $(x_0,f(x_0))$. A quadratic function is determined by three pieces of information. Once again we will use the point of tangency and the slope, but we need one more. The key idea is to use the second derivative. Just like $f$ and $TL$ have the same first derivative at $x=x_0$, we will choose our tangent parabola so that it has the same first and second derivatives as $f$ at $x=x_0$.
Let's call our quadratic function $P(x)=A\cdot(x-x_0)^2+B\cdot(x-x_0)+C$, for some constants $A$, $B$, and $C$. Our goal is to find $A$, $B$, and $C$ so that $P$ is "close to" $f$ near the point $(x_0,f(x_0))$.
[Using $(x-x_0)$ instead of just $x$ will make our calculations easier. Note the presence of $(x-x_0)$ in the tangent line formula as well.]
Note the following facts:
$P(x_0)=A\cdot(x_0-x_0)^2+B\cdot(x_0-x_0)+C=C$
$P'(x)=2A\cdot(x-x_0)+B$, so $P'(x_0)=2A\cdot(x_0-x_0)+B=B$
$P''(x)=2A$, so $P''(x_0)=2A$.
So, if $P$ and $f$ are to have the same (1) function value, (2) first derivative, and (3) second derivative at $x=x_0$, we need $C=f(x_0)$, $B=f'(x_0)$, and $A=\frac{f''(x_0)}{2}$.
Therefore, an equation for the "tangent parabola" is $P(x)=\frac{f''(x_0)}{2}\cdot(x-x_0)^2+f'(x_0)\cdot(x-x_0)+f(x_0)$
[Notice the equation for the tangent line within this formula. The tangent parabola extends the tangent line with a degree-2 term.]
Use quadratic approximation to estimate $\sqrt[3]{28}$.
Solution: The function $f$ we are trying to approximate is the cube root function, so $f(x)=\sqrt[3]{x}$. Just like in Example 1 above, we will use $(27,3)$ as our point of tangency (because $\sqrt[3]{27}$ is easy to compute).
We want to find the "tangent parabola" $P(x)=A\cdot(x-x_0)^2+B\cdot(x-x_0)+C$.
We need $C=f(27)=3$, $B=f'(27)=\frac{1}{27}$, and $A=\frac{f''(27)}{2}=-\frac{1}{2187}$.
Thus, $P(x)=-\frac{1}{2187}\cdot(x-27)^2+\frac{1}{27}\cdot(x-27)+3$.
Now we can approximate $\sqrt[3]{28}=f(28)\approx P(28)=-\frac{1}{2187}\cdot(28-27)^2+\frac{1}{27}\cdot(28-27)+3=-\frac{1}{2187}+\frac{1}{27}+3=\frac{6641}{2187}$
$\approx 3.03657978966621$
Compare this to the tangent line approximation from Example 1:
$3.03703703703704$
and the approximation from Sage:
$3.03658897187566$
This quadratic approximation gives us a percent error of about $0.0003\%$ (compared with $0.0148\%$ from linear approximation).
Let's look at a graph. The cube root function is in blue, the tangent parabola is in red, and the tangent line is in green.
Notice how much farther we can get from 27 before the approximation breaks down (compared with the tangent line).
Below is the graph of the percent error for quadratic approximation. Remember that the tangent line had percent errors less than $1\%$ for the same range of x-values - now we have percent errors less than $0.15\%$.
Use quadratic approximation to estimate $\sin\left(\frac{\pi}{5}\right)$. Use $\left(\frac{\pi}{6},\frac{1}{2}\right)$ as the point of tangency, as in Example 2 above.
Compare this percent error with the $0.494179788946525\%$ we got from linear approximation.
Here's a graph.
Here's the percent error graph. Recall, we had errors over 30% with the tangent line.
The next step would be cubic approximation. To get a cubic, we need one more piece of information. We'll make the third derivative of our "tangent cubic" equal to the third derivative of $f$ at $x=x_0$. You can continue this process as many times as you like to get a polynomial of any degree. We'll come back to this in Calculus 2.