# Visualizing Taylor polynomial approximations

## Video transcript

Let's say we've got the function
f of x is equal to e to the x. And just to get a sense
of what that looks like, let me do a rough drawing of
f of x is equal to e to the x. It would look
something like this. So that is e to the x. And what I want to do is
I want to approximate f of x is equal to e to the
x using a Taylor series approximation, or a
Taylor series expansion. And I want to do it not
around x is equal to 0. I want to do it around
x is equal to 3, just to pick another
arbitrary value. So we're going to do it
around x is equal to 3. This is x is equal to 3. This right there. That is f of 3. f of 3 is e to the third power. So this is e to the third
power right over there. So when we take the
Taylor series expansion, if we have a 0 degree
polynomial approximating it, the best we could probably do
is have a constant function going straight through
e to the third. If we do a first
order approximation, so we have a first
degree term, then it will be the tangent line. And as we add more and
more degrees to it, we should hopefully be
able to kind of contour or converge with the curve
better and better and better. And in the future, we'll
talk a little bit more about how we can
test for convergences and how well are we converging
and all that type of thing. But with that said, let's
just apply the formula that hopefully we
got the intuition for in the last video. So the Taylor series
expansion for f of x is equal to e to the
x will be the polynomial. So what's f of c? Well, if x is equal
to 3, we're saying that c is 3 in this situation. So if c is 3, f of 3 is
e to the third power. So it's e to the third power
plus-- what's f prime of c? Well f prime of x is also
going to be e to the x. You take the derivative of e
to the x, you get e to the x. That's one of the super cool
things about e to the x. So this is also f prime of x. Frankly, this is the same thing
as f the nth derivative of x. You could just keep
taking the derivative of this and you'll
get e to the x. So f prime of x is e to the x. You evaluate that at 3, you
get e to the third power again times x minus 3, c is
3, plus the second derivative our function is
still e to the x, evaluate that at 3, you get
e to the third power over 2 factorial times x minus
3 to the second power. And then we could keep going. The third derivative
is still e to the x. Evaluate that at 3. c
is 3 in this situation. So you get e to the third
power over 3 factorial times x minus 3 to the third power. And we can keep going
with this, but I think you get the general idea. But what's even more interesting
than just kind of going through the mechanics of
finding the expansion, is seeing how as we add
more and more terms, it starts to approximate e
to the x better and better and better. And our approximation gets
good further and further away from x is equal to 3. And to do that, I
used WolframAlpha, available at wolframalpha.com. And I think I typed in
Taylor series expansion e to the x and x equals 3. And it just knew what
I wanted and gave me all of this business
right over here. And it actually
calculated the expansion. And you can see it's
the exact same thing that we have over here, e to the
third plus e to the third times x minus 3. We have e to the third plus e
to the third times x minus 3 plus 1/2. They actually expanded
out the factorial. So instead of 3 factorial,
they wrote a 6 over here. And they did a bunch
of terms up here. But what's even more interesting
is that they actually graph each of these polynomials
with more and more terms. So in orange, we
have e to the x. We have f of x is
equal to e to the x. And then they tell us,
"order n approximation shown with n dots." So the order one
approximation, so that should be the situation where we
have a first degree polynomial, so that's literally-- a
first degree polynomial would be these two
terms right over here. Because this is a 0-th degree,
this is a first degree. We just have x to the
first power involved here. If we just were to plot this--
if this was our polynomial, that is plotted with 1 dot. And that is this one right
over here, with one dot, and they plot it
right over here. And we can see that
it's just a tangent line at x is equal to 3. That is x is equal to
3 right over there. And so this is the tangent line. If we add a term, now we're
getting to a second degree polynomial, because we're
adding an x squared. If you expand this out,
you'll have an x squared term, and then you'll
have another x term, but the degree of the polynomial
will now be a second degree. So let's look for two dots. So that's this one
right over here. So let's see, two dots. Two dots coming in. See, you'll notice
one, two dots. So you have two dots,
and it comes in. And this is a parabola. It's a second degree
polynomial, and then it comes back like this. But notice it does a better job,
especially around x equals 3, of approximating e to the x. It stays with the curve
a little bit longer. You add another term-- let me
do this in a new color, a color that I have not used. You add another term. Now you have a third
degree polynomial. If you have all
of these combined, if this is your polynomial, and
you were to graph that-- and so let's look for the three
dots right over here. So one, two, three. So it's this curve. Third degree polynomial is
this curve right over here. And notice, it
starts contouring e to the x a little bit sooner
than the second degree version. And it stays with it
a little bit longer. And so you have
it just like that. You add another term to it,
you add the fourth degree term to it. So now we have all of
this plus all of this. If this is your
polynomial, now you have this curve right over here. Notice every time
you add a term, it's getting better and
better at approximating e to the x further and further
away from x is equal to 3. And then if you add another
term, you get this one up here. But hopefully that
satisfies you, that we are getting closer and
closer, the more terms we add. So you can imagine it's a
pretty darn good approximation as we approach adding an
infinite number of terms.