Worked example: power series from cos(x)

WEBVTT
Kind: captions
Language: en

00:00:00.416 --> 00:00:01.533
- [Voiceover] Let's see if we can find

00:00:03.394 --> 00:00:07.200
the Maclaurin series
representation of f of x,

00:00:07.200 --> 00:00:09.633
where f of x is equal to x to the third

00:00:09.966 --> 00:00:12.767
times cosine of x squared.

00:00:12.767 --> 00:00:14.993
I encourage you to pause the
video and now try to do it.

00:00:14.993 --> 00:00:16.500
Remember, the Maclaurin series is just

00:00:16.500 --> 00:00:19.700
the Taylor series centered at zero.

00:00:19.933 --> 00:00:23.933
Let's say our goal here is
the first five non-zero terms

00:00:24.333 --> 00:00:26.635
of the Maclaurin series representation,

00:00:26.635 --> 00:00:28.600
or Maclaurin series approximation of this.

00:00:29.967 --> 00:00:31.900
I'm assuming you had paused the video

00:00:31.900 --> 00:00:33.533
and you had attempted to do this.

00:00:33.600 --> 00:00:35.267
There's a good chance
that you might have gotten

00:00:35.267 --> 00:00:36.833
quite frustrated when you did this,

00:00:36.833 --> 00:00:39.702
because in order to find a
Taylor series, Maclaurin series,

00:00:39.933 --> 00:00:42.367
we need to find the
derivatives of this function,

00:00:42.367 --> 00:00:43.566
and as soon as you start to do that,

00:00:43.566 --> 00:00:44.833
it starts to get painful.

00:00:45.134 --> 00:00:47.400
F prime of x is going to be,

00:00:47.400 --> 00:00:48.635
let's see, product rule,

00:00:48.635 --> 00:00:52.800
so it's three x squared
times cosine of x squared

00:00:53.335 --> 00:00:55.366
plus x to the third

00:00:56.000 --> 00:00:57.833
times the derivative of this thing,

00:00:57.838 --> 00:01:02.266
which is going to be two x
times negative sine of x,

00:01:02.533 --> 00:01:05.200
negative sine of x squared.

00:01:05.300 --> 00:01:06.566
Just that was be pretty painful.

00:01:06.566 --> 00:01:07.938
But it's only going to
get more and more painful

00:01:07.938 --> 00:01:10.559
as we take the second and
third and fourth derivative.

00:01:10.559 --> 00:01:11.500
We might have to take more,

00:01:11.500 --> 00:01:13.766
because some of these terms
might end up being zeros.

00:01:14.233 --> 00:01:16.066
We want the first five non-zero terms.

00:01:16.066 --> 00:01:19.466
The second derivative, this
is going to be painful.

00:01:20.334 --> 00:01:22.003
This is going to be painful.

00:01:22.003 --> 00:01:23.400
Then the third and fourth derivatives

00:01:23.400 --> 00:01:25.266
are going to be even more painful.

00:01:25.900 --> 00:01:26.867
So what do we do here?

00:01:26.867 --> 00:01:27.833
You could just do this.

00:01:27.833 --> 00:01:29.334
Let's evaluate them each at zero,

00:01:29.334 --> 00:01:31.900
and then use those for our coefficients,

00:01:31.900 --> 00:01:33.935
but you're probably guessing correctly

00:01:34.088 --> 00:01:36.266
that there's an easier way to do this.

00:01:37.166 --> 00:01:38.633
I will give you a hint.

00:01:40.733 --> 00:01:45.600
We know what the Maclaurin
series for cosine of x is.

00:01:45.866 --> 00:01:47.200
We've done that in the previous video.

00:01:47.200 --> 00:01:50.261
If you want to see that
again, there's another video.

00:01:50.266 --> 00:01:53.733
Look up "cosine Taylor series
at zero" on Khan Academy,

00:01:53.733 --> 00:01:54.966
and you'll find that.

00:01:54.966 --> 00:01:55.966
But we already know from that,

00:01:55.966 --> 00:01:59.566
and this is one of the most
famous Maclaurin series,

00:01:59.566 --> 00:02:01.866
we know that this is a g of x.

00:02:01.866 --> 00:02:03.200
We say g of x

00:02:04.200 --> 00:02:06.101
is equal to cosine of x.

00:02:07.566 --> 00:02:09.800
Well, we know how this, what this is like.

00:02:10.650 --> 00:02:13.301
There are the Maclaurin
series approximation of that

00:02:13.301 --> 00:02:16.700
is going to be one minus x squared

00:02:16.933 --> 00:02:18.666
over two factorial,

00:02:18.803 --> 00:02:23.400
plus x to the fourth over four factorial,

00:02:24.166 --> 00:02:28.566
minus x to the sixth over six factorial,

00:02:28.933 --> 00:02:30.900
plus, and I could keep
going on and on and on.

00:02:30.900 --> 00:02:32.200
You kind of see where this is going.

00:02:32.205 --> 00:02:35.933
Plus x to the eighth over eight factorial,

00:02:36.533 --> 00:02:37.633
and it just keeps going,

00:02:37.633 --> 00:02:39.619
minus, plus, on and on and on and on.

00:02:40.033 --> 00:02:42.967
But we wanted first five
terms, so this is a start.

00:02:42.967 --> 00:02:45.044
I know we wanted the first
five terms of this thing,

00:02:45.044 --> 00:02:45.733
but bear with me.

00:02:45.733 --> 00:02:47.100
We'll see how this thing right over here

00:02:47.100 --> 00:02:48.407
is going to be useful.

00:02:48.500 --> 00:02:50.433
Now that I've given you a
little bit of a reminder

00:02:50.433 --> 00:02:53.633
on the Maclaurin series
representation of cosine of x,

00:02:54.101 --> 00:02:56.666
my hint to you is, can we use this

00:02:57.267 --> 00:03:01.067
to find the Maclaurin series
representation of this,

00:03:01.233 --> 00:03:02.433
right up here?

00:03:02.433 --> 00:03:06.405
Remember, all this is, this
is x to the third times ...

00:03:06.405 --> 00:03:07.933
And I'm just rereading it for you,

00:03:07.933 --> 00:03:12.400
this is x to the third
times g of x squared.

00:03:13.219 --> 00:03:15.833
That's a sizable hint.

00:03:16.366 --> 00:03:17.733
I encourage you to pause the video again

00:03:17.733 --> 00:03:19.633
and see if you can work through this.

00:03:21.100 --> 00:03:22.266
Let me rewrite.

00:03:22.266 --> 00:03:23.833
I'm assuming you had a go at it.

00:03:23.833 --> 00:03:25.568
Let me rewrite what I just wrote.

00:03:25.568 --> 00:03:28.800
I just told you that g of x ...

00:03:29.300 --> 00:03:32.367
or f of x. F of x ...

00:03:33.012 --> 00:03:34.266
If I wanted to write it as,

00:03:35.927 --> 00:03:37.656
I guess you could say as a function,

00:03:37.656 --> 00:03:40.533
or if I want to construct it using g of x,

00:03:40.533 --> 00:03:44.159
I could rewrite it as x
to the third times ...

00:03:44.159 --> 00:03:45.367
instead of cosine of x squared,

00:03:45.367 --> 00:03:47.300
that's the same thing as g of x squared.

00:03:47.366 --> 00:03:50.133
So x to the third times g,

00:03:51.034 --> 00:03:53.000
g of x squared.

00:03:53.833 --> 00:03:57.566
G of x squared.

00:03:58.867 --> 00:04:00.066
G of x is just cosine.

00:04:00.066 --> 00:04:02.134
G of x squared is going
to be cosine of x squared.

00:04:02.466 --> 00:04:04.500
Then you're going to multiply
that times x to the third.

00:04:05.534 --> 00:04:09.900
Well, can't we just apply this
insight to the approximation?

00:04:10.502 --> 00:04:11.866
You might be asking that question.

00:04:11.933 --> 00:04:14.900
My answer to you is,
"Yes, you absolutely can."

00:04:15.300 --> 00:04:18.566
Notice, when you substitute
your xes for x squared,

00:04:18.566 --> 00:04:20.066
you'll just get another polynomial.

00:04:20.066 --> 00:04:22.000
And if you multiply
that by x to the third,

00:04:22.000 --> 00:04:23.634
you're just going to
get another polynomial.

00:04:23.634 --> 00:04:27.766
That actually will be the
Maclaurin series representation

00:04:27.766 --> 00:04:29.734
of what we started off with.

00:04:29.734 --> 00:04:32.233
We actually will get the
Maclaurin series representation

00:04:32.233 --> 00:04:34.333
of this thing right over here.

00:04:34.333 --> 00:04:36.466
So we could say that f of x

00:04:38.000 --> 00:04:39.800
is approximately equal to

00:04:40.433 --> 00:04:42.700
x to the third times

00:04:43.366 --> 00:04:44.700
x to the third times ...

00:04:44.700 --> 00:04:46.667
Let me get myself some
space right over here.

00:04:47.304 --> 00:04:49.500
G of x squared.

00:04:49.804 --> 00:04:52.400
Over here, this is
approximation for g of x,

00:04:52.400 --> 00:04:53.873
and if we kept going on and on forever,

00:04:53.873 --> 00:04:57.000
it would be a representation of g of x.

00:04:57.233 --> 00:04:59.003
So every place where we see an x,

00:04:59.003 --> 00:05:00.433
let's replace it with an x squared.

00:05:00.533 --> 00:05:02.967
This is going to be one minus ...

00:05:03.400 --> 00:05:05.567
So x squared squared is x to the fourth,

00:05:06.401 --> 00:05:08.133
x to the fourth over two factorial,

00:05:08.133 --> 00:05:08.873
which is really just two,

00:05:08.873 --> 00:05:10.867
but I like to put the factorial there

00:05:10.867 --> 00:05:12.033
because you see the pattern.

00:05:12.400 --> 00:05:15.433
Plus, if our x is now x squared,

00:05:15.433 --> 00:05:18.100
x squared to the fourth
power is x to the eighth,

00:05:18.874 --> 00:05:22.400
x to the eighth power over four factorial,

00:05:23.233 --> 00:05:26.800
minus x squared to the sixth power

00:05:26.800 --> 00:05:31.533
is x to the 12th over six factorial,

00:05:32.167 --> 00:05:34.933
and then plus x squared to the eighth

00:05:34.933 --> 00:05:38.268
is x to the 16th power
over eight factorial,

00:05:38.667 --> 00:05:41.004
and of course, we can keep
going on and on and on.

00:05:41.007 --> 00:05:43.433
Minus, plus. But we just care
about the first five terms,

00:05:43.433 --> 00:05:45.133
the non-zero terms, and we're just saying

00:05:45.133 --> 00:05:47.139
this is an approximation, anyway.

00:05:47.139 --> 00:05:49.333
So we can say that this is going to be

00:05:49.333 --> 00:05:50.535
approximately equal to,

00:05:50.535 --> 00:05:52.000
we distribute the x to the third,

00:05:52.000 --> 00:05:54.200
and I'm going to do it
in magenta just for fun,

00:05:54.200 --> 00:05:55.968
so distribute the x to the third,

00:05:55.968 --> 00:05:57.833
we get x to the third,

00:05:58.435 --> 00:06:03.435
minus x to the seventh over two factorial,

00:06:04.166 --> 00:06:09.166
plus x to the 11th over four factorial,

00:06:10.001 --> 00:06:14.733
minus x to the 15th over six factorial,

00:06:15.400 --> 00:06:18.674
plus x to the 19th ...

00:06:19.167 --> 00:06:23.433
x to the 19th over eight factorial.

00:06:23.433 --> 00:06:25.133
That's the first five non-zero terms,

00:06:25.133 --> 00:06:26.633
and we are done.

00:06:26.633 --> 00:06:28.666
When you actually see what we got,

00:06:28.666 --> 00:06:32.233
you realize it would have
taken you forever to do this

00:06:32.233 --> 00:06:35.467
by, I guess you could say, by brute force,

00:06:35.467 --> 00:06:38.833
because you would have had
to find the 19th derivative

00:06:38.833 --> 00:06:40.169
of all of this madness.

00:06:40.169 --> 00:06:41.533
But when you realize that, "Hey, gee,

00:06:41.533 --> 00:06:43.733
"if I can just re-express this function

00:06:43.733 --> 00:06:45.967
"as, essentially,

00:06:47.490 --> 00:06:49.767
"x to a power times

00:06:50.733 --> 00:06:53.066
"something that I know
the Maclaurin series of,

00:06:53.066 --> 00:06:53.833
"especially ..."

00:06:53.833 --> 00:06:55.067
Well, if you view it this way:

00:06:55.067 --> 00:06:58.000
if I can write, if I can rewrite ...

00:06:58.000 --> 00:06:59.800
Let me say it in a less confusing way.

00:07:00.333 --> 00:07:02.267
If I can rewrite my function

00:07:02.267 --> 00:07:04.967
so it is equal to some ...

00:07:04.967 --> 00:07:06.400
Actually, I can even
throw a coefficient here.

00:07:06.400 --> 00:07:10.266
If it's equal to some A x to the n power,

00:07:10.673 --> 00:07:12.800
times some function ...

00:07:13.166 --> 00:07:14.100
Let me just use a new color.

00:07:14.100 --> 00:07:15.933
Times, purple.

00:07:16.500 --> 00:07:21.500
Times g of B,

00:07:22.766 --> 00:07:25.200
B x to some other power,

00:07:26.036 --> 00:07:28.534
where I can fairly easily,

00:07:28.534 --> 00:07:29.667
without too much computation,

00:07:29.667 --> 00:07:30.804
maybe I already know,

00:07:30.804 --> 00:07:34.534
if I know the Maclaurin series
representation of g of x,

00:07:34.867 --> 00:07:36.600
if I know what g of x is going to be,

00:07:36.600 --> 00:07:38.800
then I can do exactly what
I did just in this video.

00:07:38.800 --> 00:07:41.233
I find the Maclaurin series
representation for g,

00:07:41.233 --> 00:07:42.266
every place where I saw an x,

00:07:42.266 --> 00:07:44.366
I replaced it with what I have over here,

00:07:44.366 --> 00:07:47.633
the B x to the m power,
where m is some exponent.

00:07:47.933 --> 00:07:49.567
That will give me another polynomial,

00:07:49.567 --> 00:07:50.833
another power series,

00:07:50.833 --> 00:07:52.900
and then I multiply it time A x to the n,

00:07:52.900 --> 00:07:54.033
and that's going to, once again,

00:07:54.033 --> 00:07:54.733
give me another power series,

00:07:54.733 --> 00:07:57.702
and that will be the power
series for my original function.

00:07:58.133 --> 00:07:59.333
Very exciting.


Power series of arctan(2x)

WEBVTT
Kind: captions
Language: en

00:00:00.200 --> 00:00:02.167
- [Voiceover] What I would like us to do

00:00:02.167 --> 00:00:06.066
in this video is find the
power series representation

00:00:06.066 --> 00:00:10.589
of or find the power series
approximitation (chuckles)

00:00:10.589 --> 00:00:13.933
the power series
approximation of arctangent

00:00:13.933 --> 00:00:16.900
of two x centered at zero

00:00:16.900 --> 00:00:20.633
and let's just say we want
the first four nonzero terms

00:00:20.633 --> 00:00:24.466
of the power series
approximation of arctangent

00:00:24.466 --> 00:00:26.100
of two x centered at zero

00:00:26.100 --> 00:00:29.233
so it's essentially the
Maclaurin Series of arctangent

00:00:29.233 --> 00:00:32.266
of two x, the first four
nonzero terms of it.

00:00:32.266 --> 00:00:34.066
If you feel good about it,

00:00:34.066 --> 00:00:35.433
I encourage you to pause the video

00:00:35.433 --> 00:00:37.117
and try to work through it yourself.

00:00:38.163 --> 00:00:40.700
You might have tried to work through it

00:00:40.700 --> 00:00:42.433
and you've probably took the first

00:00:42.433 --> 00:00:43.433
derivative of it.

00:00:43.433 --> 00:00:45.633
You probably saw that hey, the derivative

00:00:45.633 --> 00:00:49.566
with respect to x of arctangent

00:00:49.566 --> 00:00:54.266
of two x is equal to
and this is a refresher

00:00:54.266 --> 00:00:55.800
if you didn't realize it the first time.

00:00:55.800 --> 00:00:58.233
It's going to be the
derivative of arctangent of x

00:00:58.233 --> 00:01:01.100
is one over one plus x squared

00:01:01.100 --> 00:01:03.440
so this is going to be

00:01:03.440 --> 00:01:05.600
the derivative of this which is two

00:01:05.600 --> 00:01:09.400
over one plus this whole thing squared.

00:01:09.400 --> 00:01:14.400
One plus, I would say
one plus four x squared

00:01:14.400 --> 00:01:18.400
and then as you tried to
find more of the terms

00:01:18.400 --> 00:01:19.866
of the Maclaurin Series,

00:01:19.866 --> 00:01:22.000
you would have taken
more derivatives of this

00:01:22.000 --> 00:01:23.833
and it would have gotten very hairy,

00:01:23.833 --> 00:01:25.700
very fast if especially if you're looking

00:01:25.700 --> 00:01:28.366
for the first four nonzero terms.

00:01:28.366 --> 00:01:29.766
You probably realize hey,

00:01:29.766 --> 00:01:31.400
there must be some type of an insight

00:01:31.400 --> 00:01:33.700
that I hadn't fully appreciated yet

00:01:33.700 --> 00:01:36.166
when I just tried to just power through

00:01:36.166 --> 00:01:38.866
or no pun intended, power through

00:01:38.866 --> 00:01:40.333
finding the power series,

00:01:40.333 --> 00:01:42.542
the first four nonzero
terms of the power series

00:01:42.542 --> 00:01:45.133
centered zero of arc tangent of two x.

00:01:45.133 --> 00:01:47.900
You are right, there
is a key insight here.

00:01:47.900 --> 00:01:50.100
The key insight here is well,

00:01:50.100 --> 00:01:52.266
instead of doing it directly,

00:01:52.266 --> 00:01:54.233
let's see if we could
find the power series

00:01:54.233 --> 00:01:57.500
representation, the first
four terms of this thing

00:01:57.500 --> 00:02:01.133
right over here and then we
can take the antiderivative

00:02:01.133 --> 00:02:02.800
of that to find the power series

00:02:02.800 --> 00:02:04.548
of arctangent of two x making sure

00:02:04.548 --> 00:02:05.900
that we get the constant right

00:02:05.900 --> 00:02:09.000
that it satisfies the fact
that we are being centered

00:02:09.000 --> 00:02:12.009
at zero, so I know what
you're thinking now.

00:02:12.009 --> 00:02:13.800
Well that seems like it's getting us

00:02:13.800 --> 00:02:15.159
to the exact same issue.

00:02:15.159 --> 00:02:18.133
If I want to find the power
series representation of this,

00:02:18.133 --> 00:02:19.266
the first four terms of it,

00:02:19.266 --> 00:02:21.000
I'm still having to take
the derivative of this

00:02:21.000 --> 00:02:23.333
multiple times it seems just as hard

00:02:23.333 --> 00:02:26.200
but this is the key insight
I guess you could say.

00:02:26.200 --> 00:02:29.263
The key insight is let's just say f of x

00:02:30.124 --> 00:02:31.642
which of course is the derivative

00:02:31.642 --> 00:02:32.966
of arctangent of two x

00:02:32.966 --> 00:02:35.400
is two over one

00:02:35.400 --> 00:02:38.033
plus four x squared.

00:02:38.709 --> 00:02:42.953
Now, if we had another function

00:02:42.953 --> 00:02:44.467
that cleans it up a little bit

00:02:44.467 --> 00:02:45.933
so that we don't get all these hairiness

00:02:45.933 --> 00:02:48.100
when we take the derivatives.

00:02:48.100 --> 00:02:50.466
Let's say we had another function g of x,

00:02:50.466 --> 00:02:52.300
I'm using the color that I have not used.

00:02:53.192 --> 00:02:56.133
Let's say, that I have g of x

00:02:56.133 --> 00:03:00.033
is equal to one over one plus x.

00:03:00.033 --> 00:03:02.800
This is an interesting thing
because it's really easy

00:03:02.800 --> 00:03:06.623
and this is the same thing as one plus x

00:03:06.623 --> 00:03:08.300
to the negative one power.

00:03:08.300 --> 00:03:11.166
g of x is interesting
because it's really easy

00:03:11.166 --> 00:03:13.633
to take its derivatives.

00:03:13.633 --> 00:03:15.866
For example, g prime of x

00:03:15.866 --> 00:03:18.333
is going to be equal to chain rule

00:03:18.333 --> 00:03:19.866
derivative one plus x is just one

00:03:19.866 --> 00:03:22.800
so it's going to be equal
to negative one plus x

00:03:22.800 --> 00:03:24.333
to the negative two power

00:03:24.333 --> 00:03:26.100
if I want to take the
second derivative of that.

00:03:26.100 --> 00:03:28.756
g prime prime of x that's
going to be negative two

00:03:28.756 --> 00:03:31.617
times negative one it's
two times one plus x

00:03:31.617 --> 00:03:33.566
to the negative three power.

00:03:33.566 --> 00:03:37.994
If I want to take the
third derivative of that,

00:03:37.994 --> 00:03:39.500
that's going to be, let's see.

00:03:39.500 --> 00:03:41.566
Negative three times two its negative six

00:03:41.566 --> 00:03:44.700
times one plus x to the
negative four power.

00:03:44.700 --> 00:03:45.633
I know you're saying, "Sal,

00:03:45.633 --> 00:03:47.133
"aren't we worried about this?

00:03:47.133 --> 00:03:47.933
"Why are you doing this?"

00:03:47.933 --> 00:03:49.666
Well just bare with me for a second.

00:03:49.666 --> 00:03:51.600
Just said quickly, I was able to find

00:03:51.600 --> 00:03:53.966
the first three derivatives of g of x

00:03:53.966 --> 00:03:57.133
and it's very easy then to
find the first four terms

00:03:57.133 --> 00:03:58.900
of its power series representation

00:03:58.900 --> 00:04:00.066
especially it's Maclaurin,

00:04:00.066 --> 00:04:01.433
that's Maclaurin series

00:04:01.433 --> 00:04:03.489
if the power series centered at zero.

00:04:03.489 --> 00:04:05.400
We just have to evaluate
each of these at zero.

00:04:05.400 --> 00:04:08.933
g of zero is equal to one,

00:04:08.933 --> 00:04:10.966
g prime of zero

00:04:11.889 --> 00:04:13.920
is equal to negative one.

00:04:13.920 --> 00:04:16.300
g prime, prime of zero,

00:04:17.546 --> 00:04:19.215
so one plus zero and
then the negative three,

00:04:19.215 --> 00:04:21.200
that's just one times two is equal to two

00:04:21.200 --> 00:04:25.566
and then the third
derivative evaluated at zero

00:04:25.566 --> 00:04:27.966
is equal to negative six.

00:04:27.966 --> 00:04:31.017
I could write the g of x

00:04:32.678 --> 00:04:34.261
is approximately equal,

00:04:34.261 --> 00:04:36.200
so I'm just going to do
the first four terms here

00:04:36.200 --> 00:04:39.133
is going to be g of zero which is one

00:04:39.133 --> 00:04:41.966
minus g prime of zero times x.

00:04:41.966 --> 00:04:45.633
That's minus one times
x, so that's negative x

00:04:47.817 --> 00:04:50.800
plus g prime, prime of zero

00:04:50.800 --> 00:04:54.900
two over two factorial times x squared.

00:04:54.900 --> 00:04:56.766
Well this is just one times x squared

00:04:56.766 --> 00:04:58.066
so let me just write that.

00:04:58.419 --> 00:05:03.323
That's just going to be plus x squared

00:05:03.323 --> 00:05:08.250
and then we have plus g
prime, prime, prime of zero

00:05:08.250 --> 00:05:10.833
which is negative six over three factorial

00:05:10.833 --> 00:05:12.242
times x to the third.

00:05:12.242 --> 00:05:14.133
Well three factorials are six

00:05:14.133 --> 00:05:16.466
so negative six divided by
six is just negative one.

00:05:16.466 --> 00:05:19.300
That's going to be
negative x to the third,

00:05:20.300 --> 00:05:24.100
negative x to the third and
I know what you're thinking.

00:05:24.100 --> 00:05:26.167
"All right Sal, so you just
started with a hard problem

00:05:26.167 --> 00:05:27.733
"and you gave yourself
a much easier problem

00:05:27.733 --> 00:05:29.666
"to find the power series representation.

00:05:29.666 --> 00:05:30.907
"How is this useful?"

00:05:30.907 --> 00:05:33.466
Well this is the key insight
that I've been promising

00:05:33.466 --> 00:05:35.133
throughout this video so far.

00:05:35.133 --> 00:05:39.600
The key insight, the
long promised key insight

00:05:39.600 --> 00:05:42.800
is that and I'm finding a
suitable color for a key insight

00:05:42.800 --> 00:05:44.866
is that we can write f of x.

00:05:44.866 --> 00:05:48.166
Notice f of x is just two times,

00:05:48.166 --> 00:05:51.100
f of x is two times

00:05:51.100 --> 00:05:54.867
g of four x squared.

00:05:54.867 --> 00:05:58.666
Notice you replace your
x's with a four x squared.

00:05:58.666 --> 00:06:00.942
You're going to have one
over one plus four x squared

00:06:00.942 --> 00:06:02.767
and then you multiply that
whole thing times two,

00:06:02.767 --> 00:06:04.600
you get this thing right over here.

00:06:06.245 --> 00:06:07.733
If f of x is equal to that

00:06:07.733 --> 00:06:10.200
then f of x is power series representation

00:06:10.200 --> 00:06:13.166
its just going to be
taking this power series

00:06:13.166 --> 00:06:14.800
or at least the first four terms of it

00:06:14.800 --> 00:06:17.366
and replacing the x's with four x squares

00:06:17.366 --> 00:06:19.767
and then multiplying the
whole thing times two,

00:06:19.767 --> 00:06:21.100
so let's do that.

00:06:21.776 --> 00:06:24.527
We can write

00:06:24.527 --> 00:06:25.900
that f of x,

00:06:26.684 --> 00:06:28.666
so we could write the f of x

00:06:30.373 --> 00:06:32.500
is going to be approximately equal to

00:06:33.669 --> 00:06:36.733
two times this thing,

00:06:36.733 --> 00:06:39.573
a value when x is equal to four x squared.

00:06:39.573 --> 00:06:43.800
It is one minus instead of an x,

00:06:43.800 --> 00:06:46.233
I'm going to write a four x squared

00:06:46.233 --> 00:06:48.659
plus x squared but instead of an x,

00:06:48.659 --> 00:06:50.767
I have a four x squared squared.

00:06:50.767 --> 00:06:54.433
This is plus four x squared squared.

00:06:54.433 --> 00:06:56.966
Well that's going to
be 16 x to the fourth,

00:06:56.966 --> 00:06:57.966
so let me just write that,

00:06:57.966 --> 00:07:02.400
that's going to be plus 16 x to the fourth

00:07:02.400 --> 00:07:04.100
and finally minus x to the third

00:07:04.100 --> 00:07:05.733
but now an x is four x squared

00:07:05.733 --> 00:07:09.833
so it's minus four x
squared to the third power.

00:07:09.833 --> 00:07:12.966
Well that's going to be 64 x to the sixth.

00:07:12.966 --> 00:07:17.099
Let me write that, minus 64

00:07:17.099 --> 00:07:18.966
x to the sixth power

00:07:18.966 --> 00:07:21.302
and then we could say
that this is going to be

00:07:21.302 --> 00:07:23.200
so f of x is approximately equal to,

00:07:23.200 --> 00:07:28.100
distribute the two, two
minus eight x squared

00:07:28.100 --> 00:07:31.100
plus 32 x to the fourth

00:07:31.100 --> 00:07:34.533
minus 128 x to the sixth.

00:07:34.533 --> 00:07:37.500
Just like that with a little
bit of a substitution,

00:07:37.500 --> 00:07:40.900
I was able to reasonably
a non hairy fashion

00:07:40.900 --> 00:07:43.500
find the first four nonzero terms

00:07:43.500 --> 00:07:47.767
of the power series of two
over one plus four x squared

00:07:47.767 --> 00:07:49.633
which is the derivative,

00:07:49.633 --> 00:07:51.300
which is going to be the derivative

00:07:51.300 --> 00:07:55.200
of the power series of arctangent

00:07:55.200 --> 00:07:57.100
of two x.

00:07:57.100 --> 00:07:59.500
Let's write this down,
so I'm going to write,

00:07:59.500 --> 00:08:01.300
I'm going to write down,

00:08:02.023 --> 00:08:04.200
so arctangent of two x,

00:08:05.430 --> 00:08:09.356
arctangent of two x

00:08:09.925 --> 00:08:12.633
which is equal to an antiderivative

00:08:12.633 --> 00:08:15.266
of f of x,

00:08:16.896 --> 00:08:21.033
dx which is going to be
equal to an antiderivative

00:08:21.033 --> 00:08:22.800
of this whole, all of this business.

00:08:22.800 --> 00:08:27.667
It's the antiderivative
of two minus eight,

00:08:27.667 --> 00:08:31.533
minus eight x squared plus 32

00:08:31.533 --> 00:08:34.833
x to the fourth minus 128

00:08:34.833 --> 00:08:36.466
x to the sixth.

00:08:36.466 --> 00:08:38.933
Actually let me make this approximate

00:08:38.933 --> 00:08:42.033
because now of course
we're doing approximation

00:08:42.033 --> 00:08:43.367
with the power series.

00:08:43.367 --> 00:08:46.533
Dx and what is this going to be equal to?

00:08:46.533 --> 00:08:50.766
We get approximately equal to

00:08:50.766 --> 00:08:52.900
well I'm going to have a constant there.

00:08:52.900 --> 00:08:53.966
Let me write the constant first

00:08:53.966 --> 00:08:56.233
because when we write our power
series or Maclaurin Series,

00:08:56.233 --> 00:08:58.000
the first term is the constant term.

00:08:58.000 --> 00:09:00.833
It's our function evaluated to add zero.

00:09:00.833 --> 00:09:02.066
We're going to have a constant,

00:09:02.066 --> 00:09:03.666
if I take the antiderivative of two,

00:09:03.666 --> 00:09:07.233
that's going to be plus two x.

00:09:07.233 --> 00:09:10.266
The antiderivative of this,
let's see, x to the third

00:09:10.266 --> 00:09:11.656
divide eight by three

00:09:11.656 --> 00:09:16.103
so it's negative 8/3 x to the third power

00:09:16.103 --> 00:09:21.103
then plus 32 x to the fifth

00:09:21.127 --> 00:09:23.100
over five

00:09:23.100 --> 00:09:27.833
minus 128 x to the seventh

00:09:27.833 --> 00:09:30.400
over seven.

00:09:30.400 --> 00:09:32.166
We're in the home stretch.

00:09:32.166 --> 00:09:34.866
We've got at least four nonzero terms,

00:09:34.866 --> 00:09:35.900
if this is nonzero

00:09:35.900 --> 00:09:37.666
there's going to be five nonzero terms

00:09:37.666 --> 00:09:38.900
but now let's just make sure

00:09:38.900 --> 00:09:41.166
that our constant is
appropriate for arctangent

00:09:41.166 --> 00:09:42.133
of two x.

00:09:42.133 --> 00:09:44.800
This is essentially
evaluate to what arctangent

00:09:44.800 --> 00:09:49.766
of when this function,
when x is equal to zero.

00:09:49.766 --> 00:09:52.400
What is arctangent of zero?

00:09:52.400 --> 00:09:54.700
Remember this is centered at zero

00:09:54.700 --> 00:09:56.166
so we better get it right there.

00:09:56.166 --> 00:09:58.233
That's just the most basic thing

00:09:58.233 --> 00:10:00.600
if we're doing the Maclaurin
Series representation.

00:10:00.600 --> 00:10:01.833
We're centering at zero

00:10:01.833 --> 00:10:05.766
so our approximation evaluated zero

00:10:05.766 --> 00:10:08.200
better be the same thing as
a function of evaluated zero.

00:10:08.200 --> 00:10:11.000
Well arctangent of two times zero

00:10:11.000 --> 00:10:12.633
is just going to be zero

00:10:12.633 --> 00:10:15.833
and so this thing when
you evaluate it at zero,

00:10:15.833 --> 00:10:18.166
this gets to C, so this gets to C

00:10:18.166 --> 00:10:20.300
must be equal to zero.

00:10:20.300 --> 00:10:25.133
C must be equal to zero if
we want this thing to be zero

00:10:25.133 --> 00:10:26.700
when X is equal to zero.

00:10:26.700 --> 00:10:29.000
Just like that we're done.

00:10:29.783 --> 00:10:32.496
We've been able to figure
out that arctangent

00:10:32.496 --> 00:10:33.953
of two x

00:10:34.645 --> 00:10:36.667
is approximately equal to

00:10:37.251 --> 00:10:41.866
two x minus 8/3 x to the third power

00:10:41.866 --> 00:10:45.866
plus 32 over five x to the fifth

00:10:45.866 --> 00:10:50.800
minus 128 over seven x to the seven.

00:10:50.800 --> 00:10:51.933
If we wanted more terms,

00:10:51.933 --> 00:10:53.566
we could have gotten more terms

00:10:53.566 --> 00:10:55.233
by just doing what we just did

00:10:55.233 --> 00:10:57.066
but doing it for more terms.

00:10:57.066 --> 00:11:01.267
Hopefully you enjoyed
that fairly hairy problem

00:11:01.267 --> 00:11:03.533
but as you saw it's not
as hairy as we thought

00:11:03.533 --> 00:11:04.600
it was going to be.


Euler's method program code

WEBVTT
Kind: captions
Language: en

00:00:00.266 --> 00:00:01.833
- [Voiceover] In the first
video on Euler's Method

00:00:01.833 --> 00:00:03.603
we walked through an example

00:00:03.603 --> 00:00:07.200
where we were trying to approximate

00:00:07.200 --> 00:00:10.061
the solution to y prime is equal to y

00:00:10.061 --> 00:00:11.633
using the initial condition,

00:00:11.633 --> 00:00:14.400
start when x is equal
to zero y equals one.

00:00:14.400 --> 00:00:15.789
And you're probably thinking to yourself,

00:00:15.789 --> 00:00:18.133
well, it's very nice that
Sal was doing that by hand

00:00:18.133 --> 00:00:21.501
and it felt very home-brewed.

00:00:21.501 --> 00:00:22.633
But this looks like something

00:00:22.633 --> 00:00:24.766
that would be a good job for computers.

00:00:24.766 --> 00:00:26.833
And if you were thinking
that, you are right

00:00:26.833 --> 00:00:29.992
and that is why I took
a little time last night

00:00:29.992 --> 00:00:32.700
to actually write a computer program

00:00:32.700 --> 00:00:35.700
that implements Euler's Method.

00:00:35.700 --> 00:00:37.833
And so, what I want to
do in this video is one,

00:00:37.833 --> 00:00:39.809
show you how to use this program I had

00:00:39.809 --> 00:00:42.300
and it's sitting and I'll put
an annotation on this video

00:00:42.300 --> 00:00:43.766
so that you can click right to it,

00:00:43.766 --> 00:00:46.000
but it's sitting on the
tutorial on Khan Academy

00:00:46.000 --> 00:00:49.233
that is about Euler's Method.

00:00:49.233 --> 00:00:52.700
And so, let's first talk
about how to use this thing.

00:00:52.700 --> 00:00:54.900
So this first thing, this
first variable right over here

00:00:54.900 --> 00:00:57.609
xStep, this is how much we want to step.

00:00:57.609 --> 00:01:00.933
This is how much we want
to increase x by for each

00:01:00.933 --> 00:01:03.300
when we want to find each next point

00:01:03.300 --> 00:01:04.597
in our approximation.

00:01:04.597 --> 00:01:07.901
So in our right here xStep is one,

00:01:07.901 --> 00:01:09.300
we could make this point five,

00:01:09.300 --> 00:01:10.403
we could make this two,

00:01:10.403 --> 00:01:12.100
we could make this .001.

00:01:12.100 --> 00:01:13.869
As we see in the first video,

00:01:13.869 --> 00:01:15.500
the lower the number here

00:01:15.500 --> 00:01:19.366
the more precise of an
approximation we're going to get.

00:01:19.366 --> 00:01:20.400
On these next two variables

00:01:20.400 --> 00:01:21.733
are things that you might want to tweak.

00:01:21.733 --> 00:01:22.900
These are the initial conditions.

00:01:22.900 --> 00:01:24.166
This is the starting x.

00:01:24.166 --> 00:01:25.333
And when we're at the starting x

00:01:25.333 --> 00:01:27.220
we're assuming that
the particular solution

00:01:27.220 --> 00:01:29.700
will contain that starting y.

00:01:29.700 --> 00:01:30.966
So, the way it's set right now

00:01:30.966 --> 00:01:35.194
it says hey, the .01 is in
the particular solution.

00:01:35.194 --> 00:01:37.434
And if you go a little bit lower

00:01:37.434 --> 00:01:39.366
this is the function slope at point.

00:01:39.366 --> 00:01:42.200
I guess I could have called
it derivative at point as well

00:01:42.200 --> 00:01:45.200
or tangent slope at point.

00:01:45.200 --> 00:01:48.233
Those would involve legitimate
name for this function.

00:01:48.233 --> 00:01:50.867
This is really where I define

00:01:50.867 --> 00:01:52.866
what the differential equation is.

00:01:52.866 --> 00:01:53.833
And so you see it says like,

00:01:53.833 --> 00:01:56.433
it just says return y right over here.

00:01:56.433 --> 00:01:58.733
What it's saying is what
it's going to return

00:01:58.733 --> 00:02:01.146
is the slope at that point

00:02:01.146 --> 00:02:03.533
and you pass it at x and y

00:02:03.533 --> 00:02:05.366
and then it will give you
the slope of the point.

00:02:05.366 --> 00:02:08.034
So this is saying that the slope
of that point is equal to y

00:02:08.034 --> 00:02:10.200
or another way interpreting it is

00:02:10.200 --> 00:02:12.766
is that y prime is equal to y.

00:02:12.766 --> 00:02:15.400
And so, this is the way it's defined now.

00:02:15.400 --> 00:02:18.000
The differential equation
that we looked at

00:02:18.000 --> 00:02:19.733
in the first introductory video

00:02:19.733 --> 00:02:22.666
that at any point the derivative
is going to be equal to y.

00:02:22.666 --> 00:02:24.633
And since we stepped by one we see that.

00:02:24.633 --> 00:02:27.566
Where the .01, our
slope is going to be one

00:02:27.566 --> 00:02:30.199
until our next step, until
we increase our x by one

00:02:30.199 --> 00:02:31.379
we get to this point.

00:02:31.379 --> 00:02:32.633
Now our slope is two.

00:02:32.633 --> 00:02:35.733
We increase x by one and
then our y goes up by two.

00:02:35.733 --> 00:02:37.933
Now our slope is four.

00:02:37.933 --> 00:02:42.133
We increase x by one,
we increase y by four.

00:02:42.133 --> 00:02:44.166
Now we could do a different function here.

00:02:44.166 --> 00:02:48.066
You could say that dy,
dx is equal to negative x

00:02:48.066 --> 00:02:50.366
divided by Y.

00:02:50.366 --> 00:02:53.366
And we would get something like this.

00:02:54.073 --> 00:02:56.866
If our xStep is just one,

00:02:56.866 --> 00:02:58.033
if we have this initial condition

00:02:58.033 --> 00:03:01.366
our initial condition could
be something like that

00:03:01.366 --> 00:03:03.133
and you say even with an xStep of one

00:03:03.133 --> 00:03:04.633
something as course as that

00:03:04.633 --> 00:03:07.633
we're getting a pretty good
approximation right over here

00:03:07.633 --> 00:03:09.500
and if we want to get
a better approximation

00:03:09.500 --> 00:03:10.466
we can make this smaller.

00:03:10.466 --> 00:03:13.333
0.5 is even better.

00:03:13.333 --> 00:03:16.066
If we wanted to get even better, 0.1.

00:03:16.066 --> 00:03:17.650
And you might have noticed something

00:03:17.650 --> 00:03:18.730
that just happened here.

00:03:18.730 --> 00:03:21.366
This thing got wacky as we got,

00:03:21.366 --> 00:03:23.833
as we started dividing by,

00:03:23.833 --> 00:03:28.833
as we started getting
close to dividing by zero.

00:03:29.000 --> 00:03:29.992
And this is a reminder

00:03:29.992 --> 00:03:31.928
that this is really just
an approximation tool.

00:03:31.928 --> 00:03:35.633
We're not analytically
finding the actual solution.

00:03:35.633 --> 00:03:37.525
We're just stepping from, you know,

00:03:37.525 --> 00:03:40.366
x equals zero to x equals point
one to x equals point two,

00:03:40.366 --> 00:03:42.842
and we're using the slopes
at each of those points

00:03:42.842 --> 00:03:44.766
and were you able to figure out the slope

00:03:44.766 --> 00:03:46.166
based on this function

00:03:46.166 --> 00:03:50.767
to figure out what their
next x and y should be.

00:03:50.767 --> 00:03:52.566
So I encourage you to play with this.

00:03:52.566 --> 00:03:53.500
It's actually a lot of fun.

00:03:53.500 --> 00:03:57.333
You can see how you get a
much better approximation

00:03:57.333 --> 00:04:01.266
as you, let me go back to
what we originally had.

00:04:01.266 --> 00:04:03.333
You can see how you get a
much better approximation

00:04:03.333 --> 00:04:07.992
as you get your xSteps
being close and closer

00:04:07.992 --> 00:04:09.666
and closer to zero.

00:04:09.666 --> 00:04:12.325
So, this is you'll notice
now when you just...

00:04:12.325 --> 00:04:16.233
We have an xStep of 0.1 at x equals one.

00:04:16.233 --> 00:04:18.066
This is getting pretty close to E.

00:04:18.066 --> 00:04:20.900
It's probably doing a pretty good job

00:04:20.900 --> 00:04:25.900
of simulating the exponential function y

00:04:26.463 --> 00:04:28.866
is equal E, y equals E to the x.

00:04:28.866 --> 00:04:30.870
So the main things to know
about, this is your xStep,

00:04:30.870 --> 00:04:33.333
these right over here are
your initial conditions,

00:04:33.333 --> 00:04:34.233
your x and y.

00:04:34.233 --> 00:04:36.266
And whatever you put in here,

00:04:36.266 --> 00:04:39.900
you're gonna say that
dy, dx is equal to that.

00:04:39.900 --> 00:04:42.366
Notice I say assumes that
your differential equation

00:04:42.366 --> 00:04:43.900
can be expressed as y prime

00:04:43.900 --> 00:04:46.625
is equal to a function of x and y

00:04:46.625 --> 00:04:48.433
which is also a function of x.

00:04:48.433 --> 00:04:50.433
And so, whatever you put here,

00:04:50.433 --> 00:04:53.392
that's essentially your
function of x and y of x.

00:04:53.392 --> 00:04:55.866
So if you just have y prime
is equal to negative x or y

00:04:55.866 --> 00:04:59.215
you put negative x divided by y,

00:04:59.215 --> 00:05:02.700
negative x divided by y over here.

00:05:02.700 --> 00:05:03.933
All of these is actually no way.

00:05:03.933 --> 00:05:06.291
I'd have to raise the
initial condition here

00:05:06.814 --> 00:05:08.600
to do something like that.

00:05:08.600 --> 00:05:11.566
And if you want to now know
how this program works,

00:05:11.566 --> 00:05:12.642
if you want to modify this

00:05:12.642 --> 00:05:14.866
and I encourage you to
modify it, make it better

00:05:14.866 --> 00:05:17.366
because this I just kind of
hacked this together last night.

00:05:17.366 --> 00:05:20.266
I'll now explain what the
rest of the program is doing.

00:05:20.266 --> 00:05:22.004
So these are all the variables

00:05:22.004 --> 00:05:25.313
for kind of establishing
for drawing the graph paper.

00:05:25.313 --> 00:05:27.233
This is our minimum x, minimum y,

00:05:27.233 --> 00:05:28.866
maximum x and maximum y.

00:05:28.866 --> 00:05:30.633
They kind of fall off
the page right over here.

00:05:30.633 --> 00:05:32.333
You have your x and y offset.

00:05:32.333 --> 00:05:34.558
If you change it you'll notice,

00:05:34.558 --> 00:05:36.900
if you change your xOffset it shows

00:05:36.900 --> 00:05:38.866
how much we move to the right or the left.

00:05:38.866 --> 00:05:43.367
The yOffset it moves
everything up or down.

00:05:43.367 --> 00:05:45.933
The background, that's
just the background color

00:05:45.933 --> 00:05:47.033
that we are...

00:05:47.033 --> 00:05:49.486
The background color for our canvas.

00:05:49.486 --> 00:05:51.466
Then the xScale is
really just trying to say

00:05:51.466 --> 00:05:55.033
well, how many of the pixels

00:05:55.033 --> 00:05:58.633
result to kind of one
incremental step in x

00:05:58.633 --> 00:06:00.809
or one incremental step in y.

00:06:00.809 --> 00:06:01.962
I'm sure I probably
could have tweaked this

00:06:01.962 --> 00:06:04.166
a little bit better to factor the offset

00:06:04.166 --> 00:06:05.466
and that's probably one of the reasons why

00:06:05.466 --> 00:06:07.000
I'm falling off the screen.

00:06:07.000 --> 00:06:09.467
But anyway, you can modify it if you like.

00:06:09.467 --> 00:06:11.076
These next two functions are really

00:06:11.076 --> 00:06:15.300
to just map between x and
y coordinates and pixels.

00:06:15.300 --> 00:06:16.866
So that's that.

00:06:16.866 --> 00:06:20.633
Then this is the color of the actual grid.

00:06:20.633 --> 00:06:22.433
You can see I could change that.

00:06:22.433 --> 00:06:24.100
I could change the color of the grid

00:06:24.100 --> 00:06:24.900
to whatever I like.

00:06:24.900 --> 00:06:26.891
I like something with a
reasonable level of contrast

00:06:26.891 --> 00:06:28.200
so I'll leave it there.

00:06:28.200 --> 00:06:29.233
And then these two things,

00:06:29.233 --> 00:06:30.669
this draws the vertical lines

00:06:30.669 --> 00:06:32.748
and then labels the numbers down here.

00:06:32.748 --> 00:06:35.643
You see this draws the vertical lines.

00:06:35.643 --> 00:06:37.700
This does the labels down here.

00:06:37.700 --> 00:06:41.333
Notice it starts at x
min, it goes up to x max.

00:06:41.333 --> 00:06:45.333
This does the same thing
for the horizontal lines

00:06:45.333 --> 00:06:48.238
so this right over here is going to go.

00:06:48.238 --> 00:06:52.076
So, it starts at the y
min, goes up to the y max,

00:06:52.076 --> 00:06:55.933
draws a bunch of lines and
also labels the y axis.

00:06:55.933 --> 00:06:57.700
So that's really just kind of the setup

00:06:57.700 --> 00:06:59.933
and then this is the actual
function that we call

00:06:59.933 --> 00:07:04.600
in order to draw our approximation.

00:07:04.600 --> 00:07:07.933
And it makes use of slope at point.

00:07:07.933 --> 00:07:09.800
So, for any point you're starting,

00:07:09.800 --> 00:07:13.533
you start your x in initX, initial x.

00:07:13.533 --> 00:07:15.173
You start your y in initial y.

00:07:15.173 --> 00:07:15.900
And then you say look,

00:07:15.900 --> 00:07:19.000
while x hasn't gotten to our maximum x yet

00:07:19.000 --> 00:07:24.000
figure out or draw a point at that point,

00:07:25.700 --> 00:07:27.446
and actually we might not even need that.

00:07:27.446 --> 00:07:29.033
I can comment that out.

00:07:29.033 --> 00:07:31.346
It doesn't change it really.

00:07:31.346 --> 00:07:32.948
That's actually my first iteration,

00:07:32.948 --> 00:07:34.335
actually let me take that out.

00:07:34.335 --> 00:07:37.901
Let me take that one out

00:07:37.901 --> 00:07:39.633
or I'll leave it here for now.

00:07:39.633 --> 00:07:42.066
You could modify it as you see fit.

00:07:42.066 --> 00:07:44.258
And then it figures out the slope.

00:07:44.258 --> 00:07:46.666
It figures out the slope at that,

00:07:46.666 --> 00:07:48.566
in that current x and y.

00:07:48.566 --> 00:07:49.658
So it uses that function.

00:07:49.658 --> 00:07:51.900
So it saying okay, let
me input that x and y

00:07:51.900 --> 00:07:53.099
and then it figures out

00:07:53.099 --> 00:07:55.766
what the derivative is at that point.

00:07:55.766 --> 00:07:57.702
And so that it uses that slope

00:07:57.702 --> 00:07:59.761
to figure out what the
next x and the next y are.

00:07:59.761 --> 00:08:02.233
The next x is gonna be x incremented

00:08:02.233 --> 00:08:04.700
by the delta that you passed to it.

00:08:04.700 --> 00:08:07.633
The next y is gonna be the current y

00:08:07.633 --> 00:08:09.467
plus the slope times the delta

00:08:09.467 --> 00:08:10.900
and then it just draws a line

00:08:10.900 --> 00:08:13.300
from the current x to the next,

00:08:13.300 --> 00:08:15.766
or the current point, the x, y point

00:08:15.766 --> 00:08:17.366
to the next x, y point.

00:08:17.366 --> 00:08:19.200
And then it makes the next x one.

00:08:19.200 --> 00:08:21.000
It makes the next x and the next y

00:08:21.000 --> 00:08:23.533
the current x and the current y,

00:08:23.533 --> 00:08:26.467
and then it just keeps on
going and going and going.

00:08:26.467 --> 00:08:29.566
And then finally, this is
actually where we call,

00:08:29.566 --> 00:08:31.433
where we call that function.

00:08:31.433 --> 00:08:33.233
And I used the variable xStep

00:08:33.233 --> 00:08:36.600
that we defined earlier
on at you know, point one,

00:08:36.600 --> 00:08:39.033
but if I change this to just...

00:08:39.033 --> 00:08:40.833
If I just change this to one

00:08:40.833 --> 00:08:42.733
you see that actually makes the change

00:08:42.733 --> 00:08:44.566
and I could actually draw
multiple approximations

00:08:44.566 --> 00:08:46.066
on the same screen.

00:08:46.066 --> 00:08:49.059
That actually might help us appreciate.

00:08:49.059 --> 00:08:51.500
That actually might help us appreciate

00:08:51.500 --> 00:08:53.336
how our approximation gets better

00:08:53.336 --> 00:08:55.900
as we get a little bit more granularity.

00:08:55.900 --> 00:09:00.866
So let's say let's draw an approximation.

00:09:01.619 --> 00:09:03.733
Approximation.

00:09:03.733 --> 00:09:05.566
And instead of having an xStep

00:09:05.566 --> 00:09:07.400
or a delta x of one every time,

00:09:07.400 --> 00:09:11.386
let's have a delta x of 0.5.

00:09:12.217 --> 00:09:13.376
And so you see it there.

00:09:13.376 --> 00:09:15.000
The delta x of 0.5

00:09:15.000 --> 00:09:18.233
it gave me a more accurate representation.

00:09:18.233 --> 00:09:20.166
Let me do one more.

00:09:20.166 --> 00:09:22.576
Just show how all these works.

00:09:23.100 --> 00:09:24.500
Stroke.

00:09:24.500 --> 00:09:26.448
Let me change the color.

00:09:26.909 --> 00:09:29.576
So for the next line of
color let me make it,

00:09:29.576 --> 00:09:31.666
I don't know, I'll make it this kind of

00:09:31.666 --> 00:09:33.534
this green blue color.

00:09:33.534 --> 00:09:35.134
Let me draw.

00:09:35.134 --> 00:09:36.766
Whoops, let's draw.

00:09:36.766 --> 00:09:40.736
Draw Approximation.

00:09:40.736 --> 00:09:43.161
I'll just have to capitalize the A.

00:09:43.900 --> 00:09:46.766
Draw Approximation

00:09:46.766 --> 00:09:49.489
and I'll make this one even more fine.

00:09:49.489 --> 00:09:50.567
So there you go.

00:09:50.567 --> 00:09:52.202
That was even a better approximation.

00:09:52.202 --> 00:09:55.315
So the blue one is the most accurate one

00:09:55.315 --> 00:09:56.433
and you can do this with a bunch of ones.

00:09:56.433 --> 00:10:00.033
We could do it with what we
saw in the very first video

00:10:00.033 --> 00:10:02.800
where we're approximating
y is equal to E to the x.

00:10:02.800 --> 00:10:04.466
Well that case, the slope at a point

00:10:04.466 --> 00:10:06.125
is equal to the Y coordinate.

00:10:06.125 --> 00:10:07.900
Y prime is equal to y

00:10:07.900 --> 00:10:09.723
and our initial condition is 01,

00:10:09.723 --> 00:10:11.068
and you see the blue one

00:10:11.068 --> 00:10:14.481
is getting really close
to y is equal E to the x

00:10:14.481 --> 00:10:18.266
but you could play with all
sorts of neat things here.

00:10:18.266 --> 00:10:20.450
So, we could do things like...

00:10:20.450 --> 00:10:22.828
So we could say that y prime is equal to

00:10:22.828 --> 00:10:25.030
I don't know, x plus y.

00:10:25.030 --> 00:10:25.871
What does that do?

00:10:25.871 --> 00:10:28.100
What if we did x minus y?

00:10:28.100 --> 00:10:30.466
Well, that's actually a pretty neat one.

00:10:30.466 --> 00:10:33.366
We could change our range.

00:10:33.366 --> 00:10:34.533
We can make our x max.

00:10:34.533 --> 00:10:36.733
Let's say we want to like
zoom in a little bit here.

00:10:36.733 --> 00:10:40.230
Let's make our x max equal to four.

00:10:40.230 --> 00:10:43.104
And now you get a little
bit more fine grained here

00:10:43.104 --> 00:10:45.346
and then you could...

00:10:45.346 --> 00:10:46.633
Let's change our initial conditions.

00:10:46.633 --> 00:10:49.500
What if when x is equal
to zero y is a higher y?

00:10:49.500 --> 00:10:52.566
And so you can see how your
different approximations change.

00:10:52.566 --> 00:10:55.576
Anyway, hopefully you
found that interesting.

00:10:55.576 --> 00:10:57.484
I encourage you to modify
this and understand this

00:10:57.484 --> 00:10:59.333
because the whole point of Euler's Method

00:10:59.333 --> 00:11:00.367
it's a numerical method.

00:11:00.367 --> 00:11:02.500
It's to use something like a computer

00:11:02.500 --> 00:11:06.133
in order to approximate solutions.


Worked example: Euler's method

WEBVTT
Kind: captions
Language: en

00:00:00.358 --> 00:00:03.170
- [Voiceover] Now that we are
familiar with Euler's method,

00:00:03.017 --> 00:00:06.766
let's do an exercise that
tests our mathematical

00:00:06.919 --> 00:00:11.817
understanding of it, or at
least the process of using it.

00:00:11.818 --> 00:00:13.889
So, it says consider the
differential equation:

00:00:13.889 --> 00:00:15.352
the derivative of y with respect to x

00:00:15.352 --> 00:00:17.767
is equal to three x minus two y.

00:00:17.767 --> 00:00:20.963
Let y is equal to g of x be a solution

00:00:20.963 --> 00:00:23.912
to the differential equation
with the initial condition

00:00:23.912 --> 00:00:27.294
g of zero is equal to
k where k is constant.

00:00:27.294 --> 00:00:29.349
Euler's method starting at x equals zero

00:00:29.349 --> 00:00:31.775
with the a step size of
one gives the approximation

00:00:31.775 --> 00:00:35.293
that g of two is approximately 4.5.

00:00:35.293 --> 00:00:38.729
Find the value of k.

00:00:38.729 --> 00:00:40.366
So once again, this is saying
hey, look, we're gonna start

00:00:40.366 --> 00:00:41.454
with this initial condition
when x is equal to zero,

00:00:42.246 --> 00:00:46.913
y is equal to k, we're
going to use Euler's method

00:00:46.913 --> 00:00:48.469
with a step size of one.

00:00:48.469 --> 00:00:50.373
So, we're essentially going
to use, we're going to step

00:00:50.373 --> 00:00:53.345
once from zero to one, and
then again from one to two.

00:00:53.345 --> 00:00:57.744
And then that approximation
is going to give us 4.5.

00:00:57.744 --> 00:01:00.031
And so, given that we started
at k, we should be able

00:01:00.031 --> 00:01:02.226
to figure out what k was to get us

00:01:02.226 --> 00:01:05.929
to g of two being approximated as 4.5.

00:01:05.929 --> 00:01:08.367
So with that, I encourage
you to pause the video,

00:01:08.367 --> 00:01:10.884
and try to figure this out on your own.

00:01:12.093 --> 00:01:15.889
I am assuming you have tried
to figure this out on your own.

00:01:15.889 --> 00:01:17.747
Now we can do it together.

00:01:17.747 --> 00:01:19.233
And I'll do the same thing that we did

00:01:19.233 --> 00:01:21.206
in the first video on Euler's method.

00:01:21.206 --> 00:01:25.834
I'll make a little table here
so let me make a little table.

00:01:25.834 --> 00:01:28.106
I can draw a straighter line than that.

00:01:28.106 --> 00:01:29.569
That's only marginally straighter,

00:01:29.569 --> 00:01:31.287
but it will get the job done.

00:01:31.287 --> 00:01:35.710
So let's make this column
x, I'm going to give myself

00:01:35.071 --> 00:01:37.207
some space for y, I might do some

00:01:37.846 --> 00:01:42.846
calculation here, y, and then dy/dx.

00:01:44.011 --> 00:01:46.924
Now, we can start at
our initial condition.

00:01:46.924 --> 00:01:49.362
When x is equal to zero, y is equal to k.

00:01:49.362 --> 00:01:52.430
When x is equal to zero, y is equal to k.

00:01:53.042 --> 00:01:56.980
And so, what's our derivative
going to be at that point?

00:01:56.098 --> 00:01:58.697
Well, dy/dx is equal
to three x minus two y.

00:01:59.579 --> 00:02:04.579
So in this case, it's three
times zero minus two times k,

00:02:04.768 --> 00:02:08.521
which is just equal to negative two k.

00:02:08.521 --> 00:02:11.676
And so now we can increment one more step.

00:02:11.676 --> 00:02:16.676
We have a step size of
one, so at each step

00:02:18.942 --> 00:02:23.942
we're going to increment x by one,

00:02:25.002 --> 00:02:28.159
and so we're now going to be at one.

00:02:28.177 --> 00:02:30.139
Now what's our new y going to be?

00:02:30.139 --> 00:02:32.844
Well, if we increment
x by one, and our slope

00:02:32.844 --> 00:02:36.768
is negative two k, that means
we're going to increment y

00:02:36.768 --> 00:02:40.082
by negative two k times
one, or just negative two k.

00:02:41.282 --> 00:02:42.290
So, negative two k.

00:02:43.082 --> 00:02:46.529
So k plus negative two k is negative k.

00:02:46.529 --> 00:02:49.652
So, our approximation using
Euler's method gets us

00:02:49.652 --> 00:02:53.691
the point one negative
k, and then what is going

00:02:53.691 --> 00:02:56.915
to be our slope starting at that point?

00:02:56.915 --> 00:03:01.153
So one negative k, our slope
is going to be three times

00:03:01.153 --> 00:03:06.153
our x, which is one, minus
two times our y, which is

00:03:06.516 --> 00:03:11.516
negative k now, and this is
equal to three plus two k.

00:03:12.727 --> 00:03:16.914
And now we'll do another step of one,

00:03:16.914 --> 00:03:18.966
because that's our step size.

00:03:18.966 --> 00:03:21.149
Another, whoops, I'm going to get to two.

00:03:21.149 --> 00:03:23.166
Now this is the one that
we care about right?

00:03:23.319 --> 00:03:24.945
Because we're trying to
approximate g of two.

00:03:24.945 --> 00:03:27.528
So we have to say, what
does our approximation

00:03:27.528 --> 00:03:30.769
give us for y when x is equal to two?

00:03:30.769 --> 00:03:32.650
And we're going to have
something expressed in k,

00:03:32.065 --> 00:03:33.760
but they're saying that's going to be 4.5,

00:03:34.345 --> 00:03:36.407
and then we can use that to solve for k.

00:03:36.965 --> 00:03:38.366
So what's this going to be?

00:03:38.366 --> 00:03:41.187
So if we increment by one in x,

00:03:41.187 --> 00:03:46.187
we should increment our y by
one times three plus two k.

00:03:47.548 --> 00:03:52.470
So we're going to increment
by three plus two k,

00:03:52.047 --> 00:03:53.755
or negative k plus three plus two k

00:03:54.178 --> 00:03:58.806
is just going to be three plus k.

00:03:58.806 --> 00:03:59.975
And they're telling us that our

00:03:59.975 --> 00:04:03.040
approximation gets that to be 4.5.

00:04:03.004 --> 00:04:07.299
So three plus k is equal to 4.5.

00:04:07.335 --> 00:04:09.657
So the k that we started
with must have been,

00:04:09.657 --> 00:04:12.130
if we just subtract three from both sides,

00:04:12.013 --> 00:04:14.741
this is a decimal here, it must have been

00:04:14.858 --> 00:04:19.858
k must be equal to 1.5,
and you can verify that.

00:04:19.874 --> 00:04:21.892
If this initial condition right over here,

00:04:21.892 --> 00:04:26.893
if g of zero is equal to 1.5,
then you put 1.5 over here.

00:04:28.963 --> 00:04:33.809
Then over here you would
get 4.5, and we're done.


Euler's method

WEBVTT
Kind: captions
Language: en

00:00:00.003 --> 00:00:00.839
- [Voiceover] We've already seen

00:00:01.136 --> 00:00:03.003
that if we were to start with
the differential equation,

00:00:03.003 --> 00:00:06.336
the derivative of Y with
respect to X is equal to Y

00:00:06.633 --> 00:00:08.131
and we have the initial condition

00:00:08.131 --> 00:00:11.133
that Y of zero is equal to one,

00:00:11.133 --> 00:00:13.110
but the particular solution to this
given these initial conditions,

00:00:14.001 --> 00:00:16.024
is Y of X is equal to E to the X.

00:00:16.033 --> 00:00:18.820
Or I guess we can just
Y is equal to E of the X

00:00:19.117 --> 00:00:21.866
if we didn't want to write it
with the function notation.

00:00:21.866 --> 00:00:23.182
And that's all fair and well

00:00:23.182 --> 00:00:24.267
and this works out well.

00:00:24.267 --> 00:00:26.000
This is a separable differential equation

00:00:26.000 --> 00:00:29.027
and we can integrate things quite easily.

00:00:29.027 --> 00:00:32.122
But as you will see as you
go further in the world

00:00:32.366 --> 00:00:33.371
of differential equations,

00:00:33.866 --> 00:00:36.667
most differential equations
are not so easy to solve.

00:00:36.667 --> 00:00:39.434
In fact, many of them
are impossible to solve

00:00:39.434 --> 00:00:41.467
using analytic methods.

00:00:41.467 --> 00:00:43.333
And so given that, what do you do?

00:00:43.333 --> 00:00:45.467
We've nicely described some phenomena,

00:00:45.467 --> 00:00:46.633
modeled some phenomena

00:00:46.633 --> 00:00:48.012
using the differential equations
but if you can't solve it analytically

00:00:49.002 --> 00:00:50.011
do you just give up?

00:00:51.001 --> 00:00:53.534
And the answer to that question is no.

00:00:53.633 --> 00:00:54.639
You do not just give up

00:00:55.233 --> 00:00:58.084
because we now have computers,

00:00:58.084 --> 00:01:01.333
and computers are really
good at numerical methods.

00:01:01.333 --> 00:01:03.482
Numerical methods for approximating

00:01:03.482 --> 00:01:06.084
and giving us a sense of what the solution

00:01:06.084 --> 00:01:08.009
to a differential
equation might look like.

00:01:08.009 --> 00:01:09.642
And so how do we do that?

00:01:10.533 --> 00:01:12.033
Well, in this video we can explore

00:01:12.033 --> 00:01:14.120
one of the most straightforward
numerical methods

00:01:15.002 --> 00:01:17.011
for approximating a particular solution.

00:01:18.001 --> 00:01:19.006
So what we do is,

00:01:19.006 --> 00:01:20.852
so I'm gonna draw a little table here.

00:01:22.000 --> 00:01:23.766
So, a little table here.

00:01:25.512 --> 00:01:26.004
Actually let give myself.

00:01:26.004 --> 00:01:27.970
I'm gonna do it over here
on the left hand side.

00:01:30.815 --> 00:01:32.100
A little table.

00:01:32.867 --> 00:01:36.300
So, X and then Y.

00:01:37.000 --> 00:01:38.005
XY.

00:01:38.005 --> 00:01:42.099
And then DY, DX.

00:01:42.594 --> 00:01:46.169
And you could set up a table like this
to create a slope field.

00:01:46.466 --> 00:01:47.833
You could just pick all the ...

00:01:47.833 --> 00:01:48.839
You could sample X as in Y

00:01:49.433 --> 00:01:51.967
in the XY plane,

00:01:51.967 --> 00:01:53.566
and then figure out for our first order

00:01:53.566 --> 00:01:55.133
differential equation like this,

00:01:55.133 --> 00:01:57.028
what is the slope going
to be at that point

00:01:57.028 --> 00:01:58.981
and you could construct a slope field.

00:01:59.233 --> 00:02:01.235
And we're gonna do
something kind of related

00:02:01.433 --> 00:02:03.386
but instead of trying to
construct a slope field,

00:02:03.386 --> 00:02:05.333
we're gonna start with
this initial condition.

00:02:05.333 --> 00:02:06.341
We know that Y of zero is equal to one.

00:02:07.133 --> 00:02:08.920
We know that the particular solution

00:02:08.920 --> 00:02:11.094
of this differential
equation contains this point.

00:02:11.094 --> 00:02:12.945
So, we're gonna start with that point.

00:02:12.945 --> 00:02:14.997
So we're gonna start
with X is equal to zero

00:02:14.997 --> 00:02:16.094
and let me do this in a different color.

00:02:16.967 --> 00:02:19.002
We're gonna start with X is equal to zero,

00:02:19.002 --> 00:02:20.008
Y is equal to one.

00:02:20.008 --> 00:02:23.107
Which is that point right over there.

00:02:23.899 --> 00:02:25.004
And we're gonna say, well, okay

00:02:25.004 --> 00:02:27.745
what is the derivative at that point?

00:02:27.781 --> 00:02:29.866
Well, we know the derivative at any point

00:02:29.866 --> 00:02:31.894
that's for any solution to
this differential equation

00:02:32.146 --> 00:02:35.002
the derivative is going to
be equal to the Y value.

00:02:35.002 --> 00:02:36.598
So in this case, the derivative

00:02:36.796 --> 00:02:40.642
is going to be equal to Y.
It's going to be equal to one.

00:02:41.533 --> 00:02:42.007
And in general, if the derivative

00:02:42.007 --> 00:02:43.586
just like what we saw in
the case of slope fields,

00:02:44.279 --> 00:02:46.615
as long as the derivative
is expressed as a function

00:02:46.615 --> 00:02:49.533
of Xs and Y of Xs,

00:02:49.533 --> 00:02:51.767
then you can figure out what the slope

00:02:51.767 --> 00:02:54.366
of the tangent line will be at that point.

00:02:54.366 --> 00:02:57.334
And so, you say okay,
there's a slope of one

00:02:57.334 --> 00:03:01.767
at that point so I can
depict it like that.

00:03:02.133 --> 00:03:03.875
And instead of just keep doing
that with a bunch of points

00:03:03.875 --> 00:03:05.266
we'll say okay, well let's just ...

00:03:05.266 --> 00:03:07.373
We know that the slope is changing

00:03:07.373 --> 00:03:10.002
or it's probably changing for most cases.

00:03:10.002 --> 00:03:12.768
But let's just assume it's
fixed until our next X

00:03:12.966 --> 00:03:16.739
and then use that assumption to estimate
what the next Y would be.

00:03:17.333 --> 00:03:19.000
So, what am I talking about here?

00:03:19.000 --> 00:03:20.489
So, when I talk about the next X

00:03:20.489 --> 00:03:22.001
we're talking about well, let's just step.

00:03:22.001 --> 00:03:23.767
Let's just say for the sake of simplicity,

00:03:23.866 --> 00:03:27.026
we're gonna have a delta X of one.
A change in X of one.

00:03:27.089 --> 00:03:29.130
So we're gonna step
from X equals zero now.

00:03:30.003 --> 00:03:32.636
We're gonna now step from that to

00:03:32.933 --> 00:03:35.001
X is equal to one.

00:03:35.001 --> 00:03:36.235
So we're now gonna go to ...

00:03:36.334 --> 00:03:37.009
Actually I may not use that.

00:03:37.009 --> 00:03:40.223
I used that yellow color
already for the actual graph

00:03:41.114 --> 00:03:43.000
or for the actual E to the X.

00:03:43.000 --> 00:03:44.566
So now let's say X is equal to one.

00:03:44.566 --> 00:03:47.094
Our delta X is one.

00:03:47.094 --> 00:03:49.333
So we've just added one here.

00:03:49.333 --> 00:03:49.833
And what we can do

00:03:50.233 --> 00:03:53.001
in our little approximation scheme here is

00:03:53.001 --> 00:03:55.004
well, let's just assume
that that slope was constant

00:03:55.004 --> 00:03:57.852
over that interval.

00:03:58.248 --> 00:04:00.033
So where does that get us to?

00:04:00.033 --> 00:04:03.636
Well, if Y was at one and
if I have a slope of one

00:04:03.933 --> 00:04:05.842
for one more, for one increase in X,

00:04:05.842 --> 00:04:08.166
I'm gonna increase my Y by one.

00:04:08.166 --> 00:04:10.264
So then Y is going to increase by one

00:04:10.264 --> 00:04:13.282
and is going to get to two.

00:04:13.282 --> 00:04:16.966
And we see that point right over there

00:04:16.966 --> 00:04:19.632
and you already might
see where this is going.

00:04:19.632 --> 00:04:24.266
Now, if this were actually
a point on the curve,

00:04:24.266 --> 00:04:25.533
on the solution,

00:04:25.533 --> 00:04:27.267
and if it was satisfying this,

00:04:27.267 --> 00:04:29.267
what would then the derivative be?

00:04:29.267 --> 00:04:30.766
Well, the derivative is equal to Y.

00:04:30.766 --> 00:04:31.715
The slope of the tangent line

00:04:31.715 --> 00:04:32.718
is going to be equal to Y.

00:04:33.015 --> 00:04:36.008
So, in this case, the
slope of the tangent line

00:04:36.008 --> 00:04:38.373
is now going to be equal to two.

00:04:38.373 --> 00:04:39.548
And we could depict that.

00:04:39.548 --> 00:04:41.866
Let me depict that in magenta here.

00:04:41.866 --> 00:04:46.866
So, it is going to be two.

00:04:46.867 --> 00:04:47.924
It's gonna look ...

00:04:47.924 --> 00:04:49.169
So the slope of the tangent line there

00:04:49.169 --> 00:04:51.333
is going to be two.

00:04:51.333 --> 00:04:55.808
And so, what does that tell us?
Well if we step by our delta X one more.

00:04:57.039 --> 00:04:59.362
So now our X is equal to two.

00:04:59.362 --> 00:05:04.167
What should the corresponding Y be?

00:05:04.733 --> 00:05:05.866
Well, let's see.

00:05:05.866 --> 00:05:10.866
Now for every one that we
increase in the X direction

00:05:11.002 --> 00:05:13.135
we should increase two in the Y direction

00:05:13.333 --> 00:05:14.867
because the slope is two.

00:05:14.867 --> 00:05:18.873
So, the very next one should be four.

00:05:19.467 --> 00:05:21.938
Y is equal to four.
So, we could imagine

00:05:22.433 --> 00:05:24.002
we have now kind of had a constant slope

00:05:24.002 --> 00:05:26.107
when we get to that
point right over there.

00:05:26.305 --> 00:05:27.534
And now we can do the same thing.

00:05:27.534 --> 00:05:29.525
Well if we assume DY, DX

00:05:29.525 --> 00:05:31.671
based on the differential
equation it has to be equal Y,

00:05:31.671 --> 00:05:34.330
okay, the slope of the tangent line there
is going to be the same thing as Y.

00:05:34.627 --> 00:05:36.734
It's going to be four.

00:05:36.734 --> 00:05:41.343
And so, if we step our X up by one,

00:05:41.343 --> 00:05:43.594
if we increment our X by one again,

00:05:43.594 --> 00:05:45.733
once again, we just decided
to increment by one.

00:05:45.733 --> 00:05:47.166
We could have incremented by 10,

00:05:47.166 --> 00:05:49.433
we could have incremented by .01.

00:05:49.433 --> 00:05:50.438
And you could guess which
one's going to give you

00:05:50.933 --> 00:05:51.942
a more accurate result.

00:05:52.833 --> 00:05:54.292
But if we step up by one now

00:05:54.292 --> 00:05:55.767
and our slope is four,

00:05:55.767 --> 00:05:57.533
well, we're gonna increase by ...

00:05:57.533 --> 00:05:58.535
If we increase X by one

00:05:58.733 --> 00:06:00.266
we're gonna increase Y by four.

00:06:00.266 --> 00:06:05.266
So we are going to get to eight.

00:06:06.466 --> 00:06:10.323
And so, we are at the
point three comma eight

00:06:10.323 --> 00:06:13.967
which is right over here.

00:06:13.967 --> 00:06:16.233
And so, for this next stretch,

00:06:16.233 --> 00:06:21.233
the next stretch is
going to look like that.

00:06:21.467 --> 00:06:23.674
And as you can see just by doing this,

00:06:23.674 --> 00:06:26.633
we have been able to approximate

00:06:26.633 --> 00:06:28.634
what the particular solution looks like

00:06:28.733 --> 00:06:31.458
and you might say, "Hey, so how do we know
"that's not so good of an approximation?"

00:06:32.133 --> 00:06:33.766
And my reply to you is well, yeah

00:06:33.766 --> 00:06:34.774
I mean, depends on what your goals are.

00:06:35.566 --> 00:06:36.633
But I did this by hand.

00:06:36.633 --> 00:06:38.567
I didn't even do this using a computer.

00:06:38.567 --> 00:06:43.169
And because I wanted to do it by hand
I took fairly large delta X steps.

00:06:43.466 --> 00:06:45.133
If I wanted a better approximation

00:06:45.133 --> 00:06:47.266
I could have lowered the delta X

00:06:47.266 --> 00:06:48.333
and let's do that.

00:06:48.333 --> 00:06:51.237
So let's take another scenario.
So let's do another scenario

00:06:51.633 --> 00:06:53.166
where instead of delta X equal one,

00:06:53.166 --> 00:06:59.136
let's say delta X equals 1/2.
So once again, X, Y

00:06:59.833 --> 00:07:03.489
and the derivative of Y with respect to X.

00:07:04.166 --> 00:07:05.767
So now let's say I want to take ...

00:07:05.767 --> 00:07:06.776
So we know this first point.

00:07:07.667 --> 00:07:11.740
We're given this initial condition.
When the X is zero, Y is one

00:07:12.334 --> 00:07:15.133
and so the slope of the tangent
line is going to be one.

00:07:15.133 --> 00:07:16.095
But then if we're incrementing by 1/2

00:07:16.095 --> 00:07:19.578
so then when X is, I'll
just write it as 0.5.

00:07:20.942 --> 00:07:23.541
0.5.

00:07:23.541 --> 00:07:28.336
What is our new Y going to be?
Well we're gonna assume that our slope

00:07:28.633 --> 00:07:31.551
from this to this is this
slope right over here.

00:07:31.551 --> 00:07:33.967
So our slope is one, so
if we increase X by 0.5

00:07:33.967 --> 00:07:39.010
we're gonna increase Y by 0.5
and we're going to get to 1.5.

00:07:40.000 --> 00:07:43.667
So, we can get 0.5, 1.5.

00:07:43.667 --> 00:07:45.266
We get to that point right over there.

00:07:45.266 --> 00:07:47.033
Actually you're having
trouble seeing that.

00:07:47.033 --> 00:07:49.130
This stuff right over here
is this point right over here

00:07:50.003 --> 00:07:53.008
and now our new slope is going to be 1.5.

00:07:53.008 --> 00:07:57.079
Which is going to look like.

00:07:57.871 --> 00:08:01.007
Which is going to look like
actually not quite that steep.

00:08:01.007 --> 00:08:03.009
I don't want to overstate
how good an approximation is

00:08:03.009 --> 00:08:04.442
and it's starting to
get a little bit messy

00:08:05.333 --> 00:08:06.734
but it's gonna look something like that.

00:08:06.734 --> 00:08:08.913
And what you would see if
you kept doing this process,

00:08:08.913 --> 00:08:12.775
so if your slope is now 1.5,
when you increment X by another 0.5

00:08:13.666 --> 00:08:15.167
where you get to one.

00:08:15.167 --> 00:08:19.766
So now if you increment by 0.5

00:08:19.766 --> 00:08:20.768
and your slope is 1.5,

00:08:20.966 --> 00:08:25.966
your Y is going to increment
by half of that by 0.75

00:08:26.133 --> 00:08:31.617
and so, you're gonna get to 2.25.
So now you get to one, 2.25

00:08:32.013 --> 00:08:33.105
which is this point right over here.

00:08:33.933 --> 00:08:35.767
Once again, this is a
better approximation.

00:08:35.767 --> 00:08:36.966
Remember, in the original one

00:08:36.966 --> 00:08:39.967
Y of one you know should be equal to E.

00:08:39.967 --> 00:08:43.764
Y of one in the actual
solution should be equal to E.

00:08:43.764 --> 00:08:46.109
2.7 on and on and on and on and on.

00:08:46.109 --> 00:08:51.109
Now in this one, Y of one got us to two.

00:08:51.933 --> 00:08:54.007
In this one Y of one got us to 2.25.

00:08:54.007 --> 00:08:57.013
Once again, closer to the
actual reality, closer to E.

00:08:58.003 --> 00:08:59.337
Instead of stepping by 0.5,

00:08:59.634 --> 00:09:02.933
if we stepped by 0.1 we
would get even closer.

00:09:02.933 --> 00:09:09.375
If we stepped by 0.0001 we would get
even closer and closer and closer.

00:09:10.266 --> 00:09:11.633
So there's a bunch of
interesting things here.

00:09:11.633 --> 00:09:13.534
This is actually how most
differential equations

00:09:13.534 --> 00:09:15.728
or techniques that are derived from this

00:09:15.728 --> 00:09:17.334
or that are based on numerical methods

00:09:17.334 --> 00:09:18.004
similar to this

00:09:18.004 --> 00:09:20.083
are how most differential
equations gets solved.

00:09:20.479 --> 00:09:22.002
You know it's not the exact same solution

00:09:22.002 --> 00:09:23.007
or the same method that the idea

00:09:23.007 --> 00:09:25.573
that most differential
equations are actually solved

00:09:26.266 --> 00:09:27.933
or I guess you can say simulated

00:09:27.933 --> 00:09:29.043
with a numerical method

00:09:29.043 --> 00:09:31.009
because most of them
actually cannot be solved

00:09:31.009 --> 00:09:32.376
in analytical form.

00:09:33.267 --> 00:09:35.744
Now you might be saying,
"Hey, well what method is

00:09:35.744 --> 00:09:37.356
"this one right over here called?"

00:09:37.356 --> 00:09:39.377
Well, this right over
here is called Euler's.

00:09:40.212 --> 00:09:44.005
Euler's Method
after the famous Leonhard Euler.

00:09:44.931 --> 00:09:47.166
Euler's Method.

00:09:47.166 --> 00:09:48.173
And not only actually
is this one a good way

00:09:48.866 --> 00:09:52.433
of approximating what the solution to

00:09:52.433 --> 00:09:54.367
this or any differential equation is,

00:09:54.367 --> 00:09:56.005
but actually for this differential
equation in particular

00:09:56.005 --> 00:09:57.339
you can actually even use this

00:09:57.834 --> 00:10:02.834
to find E with more and
more and more precision.

00:10:03.763 --> 00:10:05.700
Anyway, hopefully you found that exciting.


Modeling population with simple differential equation

WEBVTT
Kind: captions
Language: en

00:00:00.091 --> 00:00:02.052
- What I'd like to do in
this video is start exploring

00:00:02.052 --> 00:00:04.665
how we can model things with
the differential equations.

00:00:04.665 --> 00:00:06.202
And in this video in particular,

00:00:06.202 --> 00:00:10.395
we will explore modeling population.

00:00:11.038 --> 00:00:12.305
Modeling population.

00:00:12.647 --> 00:00:14.181
We're actually going to
go into some depth on

00:00:14.181 --> 00:00:16.035
this eventually, but here we're going

00:00:16.035 --> 00:00:17.540
to start with simpler models.

00:00:17.054 --> 00:00:19.573
And we'll see, we will stumble on using

00:00:20.059 --> 00:00:22.385
the logic of differential equations.

00:00:22.385 --> 00:00:23.420
Things that you might have seen

00:00:23.735 --> 00:00:26.581
in your algebra or your precalculus class.

00:00:26.581 --> 00:00:28.938
So, in some level, what
we're going to do here

00:00:28.938 --> 00:00:32.139
is going to be review, but
we're going to get there

00:00:32.139 --> 00:00:36.183
using the power of modeling
with differential equations.

00:00:36.552 --> 00:00:38.598
So let's just define some variables.

00:00:38.598 --> 00:00:43.598
Let's say that P is
equal to our population.

00:00:44.662 --> 00:00:49.662
And let's say that t
is, let's say that t is

00:00:49.923 --> 00:00:54.199
equal to the time that has passed in days.

00:00:54.199 --> 00:00:57.176
In days, it could have
been years or months.

00:00:57.176 --> 00:00:59.577
But let's say we're
doing the population of

00:00:59.577 --> 00:01:01.399
insects that reproduce quite quickly.

00:01:01.399 --> 00:01:06.399
So days seem like a nice
time span to care about.

00:01:06.979 --> 00:01:08.882
Now, what would be a reasonable model?

00:01:09.606 --> 00:01:12.551
Well, we could say that
the rate of change,

00:01:12.998 --> 00:01:16.511
the rate of change of our
population, with respect to time,

00:01:17.173 --> 00:01:21.637
with respect to time is, well,
a reasonable thing to say

00:01:21.637 --> 00:01:23.279
is that it's going to be proportional

00:01:23.279 --> 00:01:26.673
to the actual population,
the actual population.

00:01:26.673 --> 00:01:28.165
Why is that reasonable?

00:01:28.165 --> 00:01:30.616
Well, the larger the population,

00:01:30.616 --> 00:01:32.488
the larger the rate at any given time.

00:01:32.488 --> 00:01:34.040
If you have a thousand people, the rate

00:01:34.004 --> 00:01:36.257
at which they're reproducing
is going to be more,

00:01:36.293 --> 00:01:38.794
or a thousand insects is
going to be more insects

00:01:38.794 --> 00:01:41.396
per second, per day or per year

00:01:41.396 --> 00:01:43.633
than if you only have 10 insects.

00:01:43.633 --> 00:01:45.652
So it makes sense that the rate of growth

00:01:45.823 --> 00:01:47.748
of your population, with respect to time,

00:01:47.748 --> 00:01:51.450
is going to be proportional
to your population.

00:01:51.045 --> 00:01:52.671
And so, you know, sometimes you think of

00:01:53.076 --> 00:01:55.567
differential equations as
these daunting complex things,

00:01:55.567 --> 00:01:57.278
but notice we've just been able to express

00:01:57.278 --> 00:02:01.680
a reasonably not so complicated idea.

00:02:01.068 --> 00:02:02.493
The rate of change of population is going

00:02:03.105 --> 00:02:05.682
to be proportional to the population.

00:02:05.682 --> 00:02:07.904
And now, once we've expressed
that, we can actually

00:02:07.904 --> 00:02:10.059
try to solve this differential equation.

00:02:10.059 --> 00:02:12.185
Find a general solution, and
then we can try to put some

00:02:12.185 --> 00:02:16.271
initial conditions on there or
some states of the population

00:02:16.271 --> 00:02:19.038
that we know to actually
solve for the constants

00:02:19.038 --> 00:02:22.289
to find a particular solution.

00:02:22.289 --> 00:02:23.366
So how do we do that?

00:02:23.366 --> 00:02:25.140
And I encourage you to
pause the video at any time

00:02:25.014 --> 00:02:27.392
and see if you can solve
this differential equation.

00:02:28.457 --> 00:02:31.393
So assuming you, at least,
maybe have had an attempt at it,

00:02:31.793 --> 00:02:33.436
and you might immediately recognize that

00:02:33.436 --> 00:02:35.870
this is a separable differential equation.

00:02:35.087 --> 00:02:36.863
And in separable differential equations,

00:02:37.646 --> 00:02:39.722
we want one variable and
all the differentials

00:02:39.722 --> 00:02:42.523
involving that variable on one
side, and the other variable

00:02:42.523 --> 00:02:43.474
and all the differentials involving

00:02:43.474 --> 00:02:45.575
the other variable on the other side,

00:02:45.575 --> 00:02:47.801
and then we can integrate both sides.

00:02:47.801 --> 00:02:52.801
And once again, dP, the
derivative of P with respect to t,

00:02:53.278 --> 00:02:54.915
this isn't quite a fraction.

00:02:54.915 --> 00:02:59.181
This is the limit as our change
in P over change in time.

00:02:59.181 --> 00:03:02.407
This is our instantaneous
change, but for the sake of

00:03:02.407 --> 00:03:04.408
separable differential equations

00:03:04.408 --> 00:03:06.734
or differential equations
in general, you can treat,

00:03:06.734 --> 00:03:10.361
you can treat these, this
derivative in Leibniz notations

00:03:10.361 --> 00:03:13.137
like fractions, and you can
treat these differentials

00:03:13.137 --> 00:03:16.514
like quantities because we
will eventually integrate them.

00:03:16.514 --> 00:03:17.549
So let's do that.

00:03:17.864 --> 00:03:20.491
So, we want to put all
the Ps and dPs on one side

00:03:20.491 --> 00:03:23.267
and all the, all the things that involve t

00:03:23.267 --> 00:03:27.319
or that I guess don't
involve P on the other side.

00:03:27.319 --> 00:03:30.616
So, we could divide both sides by P.

00:03:30.616 --> 00:03:33.071
We could divide both sides
by P, and so we'll have

00:03:33.071 --> 00:03:37.123
one over P, and you have one over P

00:03:37.123 --> 00:03:39.424
here and then those will cancel,

00:03:39.424 --> 00:03:43.201
and then you can multiply
both sides times dt.

00:03:43.201 --> 00:03:45.202
We could multiply both sides times dt.

00:03:45.202 --> 00:03:48.078
Once again, treating the
differential like a quantity

00:03:48.078 --> 00:03:50.354
which isn't, it really isn't a quantity.

00:03:50.354 --> 00:03:53.005
You really have to view this as a limit of

00:03:54.127 --> 00:03:56.190
change in P over change in time.

00:03:56.757 --> 00:03:59.658
The limit as we get smaller and smaller

00:03:59.658 --> 00:04:01.984
and smaller changes in time.

00:04:01.984 --> 00:04:03.810
But for, once again, for the sake of this

00:04:03.081 --> 00:04:05.482
we can do this, and when we do that

00:04:06.098 --> 00:04:11.098
we would be left with one over P dP

00:04:13.813 --> 00:04:17.375
is equal to, is equal to

00:04:17.682 --> 00:04:22.391
k dt, is equal to k dt.

00:04:22.391 --> 00:04:26.395
Now we can integrate,
integrate both sides.

00:04:26.395 --> 00:04:29.258
Because this was a separable
differential equation,

00:04:29.258 --> 00:04:31.823
we were able to completely
separate the Ps and dPs from

00:04:31.823 --> 00:04:33.424
the things involving ts or, I guess,

00:04:33.424 --> 00:04:36.250
the things that aren't
involving Ps, and then

00:04:36.025 --> 00:04:39.376
if we integrate this side,
we would get the natural log,

00:04:39.601 --> 00:04:43.703
the natural log of the absolute
value of our population,

00:04:43.703 --> 00:04:46.229
and we could say plus
some constant if we want

00:04:46.229 --> 00:04:48.205
but we're going to get a
constant on this side as well

00:04:48.205 --> 00:04:51.682
so we could just say that's
going to be equal to,

00:04:51.682 --> 00:04:55.434
that's going to be equal to
k, it's going to be equal to

00:04:55.434 --> 00:05:00.434
k times t, k times t plus some constant.

00:05:01.106 --> 00:05:03.104
Plus some constant.

00:05:03.104 --> 00:05:05.763
I'll just call that C one, and once again

00:05:05.763 --> 00:05:08.085
I could've put a plus C
two here, but I could've

00:05:08.085 --> 00:05:10.470
then subtracted the
constant from both sides

00:05:10.047 --> 00:05:12.734
and I would just get the
constant on the right hand side.

00:05:13.742 --> 00:05:16.668
Now, how can I solve for P?

00:05:16.668 --> 00:05:18.944
Well, the natural log of
the absolute value of P

00:05:18.944 --> 00:05:21.776
is equal to this thing right over here.

00:05:21.776 --> 00:05:24.172
That means that's the same thing.

00:05:24.172 --> 00:05:26.523
That means that the absolute value of P,

00:05:26.523 --> 00:05:28.198
that means that the absolute value of P

00:05:28.198 --> 00:05:32.300
is equal to e to all this business,

00:05:32.003 --> 00:05:36.855
e to the, e to the, let
me do in the same colors,

00:05:37.152 --> 00:05:42.152
kt, kt plus,

00:05:43.609 --> 00:05:47.441
plus C one, plus C one.

00:05:47.441 --> 00:05:50.134
Now this right over
here is the same thing.

00:05:50.134 --> 00:05:52.330
Just using our exponent
properties, this is the same thing

00:05:52.033 --> 00:05:55.161
as e to the kt,

00:05:56.304 --> 00:05:59.218
e to the k times t

00:05:59.218 --> 00:06:03.457
times e, times e to the C one,

00:06:04.364 --> 00:06:06.157
e to the C one.

00:06:06.088 --> 00:06:07.590
Now this is just e to some constant,

00:06:08.382 --> 00:06:09.398
so we could just call this,

00:06:09.542 --> 00:06:12.043
let's just call that the constant C.

00:06:12.043 --> 00:06:16.008
So this is all simplified to C e,

00:06:16.716 --> 00:06:20.338
C e to the kt,

00:06:21.275 --> 00:06:24.190
to the kt.

00:06:24.559 --> 00:06:27.275
And if we assume our
population at any given time

00:06:27.275 --> 00:06:30.638
is positive then we could get rid of

00:06:30.638 --> 00:06:34.153
this absolute value sign, and
we have a general solution

00:06:34.153 --> 00:06:37.180
to this, frankly, fairly
general differential equation.

00:06:37.018 --> 00:06:37.793
We just said proportional.

00:06:37.955 --> 00:06:40.381
We haven't given what the
proportionality constant is,

00:06:40.381 --> 00:06:42.857
but we could say, if we
assume, positive population

00:06:43.318 --> 00:06:46.809
that the population is
going to be equal to

00:06:46.809 --> 00:06:51.809
some constant C times e to the kt power.

00:06:52.787 --> 00:06:55.638
To the kt power, and the
reason why I said that

00:06:55.638 --> 00:06:57.394
you've seen this before is this

00:06:57.394 --> 00:07:00.938
is just an exponential function,
and it's very likely that

00:07:00.938 --> 00:07:04.192
in algebra or in precalculus class

00:07:04.056 --> 00:07:06.414
you have modeled things
with exponential functions,

00:07:06.918 --> 00:07:08.694
and my guess is that
you've modeled things,

00:07:09.754 --> 00:07:12.371
modeled things like population.

00:07:12.371 --> 00:07:14.067
The reason why this is interesting is

00:07:14.067 --> 00:07:15.150
you now see where this is coming from.

00:07:15.897 --> 00:07:17.923
The underlying logic that's just driven

00:07:17.923 --> 00:07:20.574
by the actual differential equation.

00:07:20.574 --> 00:07:22.850
The rate of change, with respect
to time, of the population.

00:07:23.526 --> 00:07:26.602
Well, maybe it's just
proportional to population.

00:07:26.602 --> 00:07:28.403
So I'll leave you there,
and in the next video

00:07:28.403 --> 00:07:31.354
we'll do what you probably
did in the 10th or 11th grade

00:07:31.354 --> 00:07:33.141
or maybe later in your
life, it doesn't matter when

00:07:33.141 --> 00:07:35.506
you did it, where we actually look at some

00:07:35.506 --> 00:07:39.158
initial conditions to find
a particular solution.