00:00Hi everyone. So in this
00:02session, I'm going to introduce
00:03you to Euler's method and
00:05Euler's method is a method
00:06for solving differential equations and
00:08it is a numerical method,
00:10which means we can use
00:12it to solve differential equations
00:14that we can't solve algebraically.
00:17Now, for example, for example,
00:21imagine I had a differential
00:23equation like this, duide x
00:25equals y squared minus x.
00:28I can't separate the variables
00:30here. I can't apply any
00:32of the other techniques that
00:33I have shown you or
00:33I'm going to show you.
00:35There's nothing I can do
00:36except use some kind of
00:37numerical method like order's method.
00:40Now, the example I'm going
00:42to show you is actually
00:43more, well, I'm going to
00:45show you, I'm going to
00:46make two videos. One video
00:47to introduce it and show
00:49you a simple example. And
00:50then in the next video,
00:51I'll show you a more
00:52complicated example. I'm going to
00:53show you a kind of
00:54trick how to do with
00:55the calculator.
00:56as well. But this example
00:57I'm going to show you
00:58a simple example that we
00:59could do, well that we
01:01can easily solve, and just
01:03because I want to show
01:03you how it works. So
01:05the solution to this, dy
01:07dx is actually, we know
01:09this, this is just y
01:11equals x squared over two.
01:14And then it's plus c,
01:15but they give us the
01:16initial condition y equals zero
01:18and x equals zero. So
01:20it ends up c being
01:21zero. So we end up
01:22with this is my solution.
01:24So look, I don't need
01:25to use order's method because
01:27I have the solution. But
01:28as I said, I want
01:30to use this example to
01:34actually show you how it
01:34works. Now, this is the
01:38solution to this differential equation
01:39and I've actually drawn it.
01:41This is the graph of
01:42y equals x squared over
01:442. So this is what
01:46I am trying to get.
01:49Okay, now there's a formula.
01:52In the form of booklet,
01:53I'll get to that in
01:55a minute, but first I
01:56just want to explain to
01:57you how the whole thing
01:58works. Now this is a
02:00little bit complicated to get
02:01your head around, but actually,
02:03or there's method, it's actually
02:04quite a nice question, because
02:06once you get the hang
02:07of the formula, it's pretty
02:09much following the formula and
02:13come up with the answer.
02:14But it is always good
02:16to get a good understanding
02:17of what's happening. So bear
02:19with me, you might want
02:20to
02:20this video two or three
02:22times just to understand exactly
02:23what I'm saying. Essentially what
02:26they do is what Euler
02:29does is let's say we
02:30start here let's say they
02:32give us so we need
02:33us we need some point
02:34to start with so say
02:35they give us the point
02:36negative 4, 8. Now what
02:39we do is we get
02:41the gradient at this point
02:43now the gradient of the
02:44curve at this point now
02:46imagine you've imagined here we
02:47don't have the graph
02:48and we don't have the
02:49solution. Because imagine it's a
02:51really complicated differentiator. So we
02:52don't have the graph and
02:53we don't have the solution,
02:54but we do know what
02:55the derivative is and we
02:56do have a point. So
02:57I can find what the
02:59gradient is at that point.
03:01In our case, it's simple.
03:03It's just do it x,
03:04it was x. So the
03:05gradient is x and at
03:06this point, it's negative four.
03:07So the gradient is negative
03:08four. So what it does
03:11is, what our does method
03:12does is, we assume the
03:14gradient is negative four and
03:16we just make
03:16I think we assume it
03:17stays negative four for this
03:19step length. So the step
03:21length h equals one and
03:23that's, I'll get to this
03:24in the formula. It says
03:25where h is a constant
03:26step length. So h is
03:28the step length and the
03:30smaller the step length, the
03:31more accurate the, the more
03:36accurate the solution is going
03:37to be. So let me
03:38give you, let's imagine we
03:39use a step length of
03:41two. So I'm going to
03:42assume the gradient
03:44stays. I'm going to assume
03:47the gradient stays as negative
03:484, so that's negative 4.
03:51For a step length of
03:532, so that goes from
03:54here to here, that's an
03:56x -step length of 2.
03:59So I assume the gradient
04:00is negative 2. I'm sorry,
04:02negative 4 for that, for
04:04this length, from negative 4
04:06to 2. Now you can
04:07see it's clearly not a
04:10great approximation. It's good here.
04:12Maybe it's good enough down
04:14to here, but it's starting
04:15to go away from the
04:16curve. Now at this point,
04:19we say, okay, stop. Next
04:20step, what's the gradient here?
04:22We go to this, it's
04:23x, so we sub in,
04:25oh, it's just negative two.
04:26So now I'm gonna assume
04:28the gradient is negative two.
04:31First step length of two,
04:33done. Now we've gone way
04:34off this curve. Go back
04:36to here, what's the gradient
04:38at zero? Well, it's zero,
04:39so for two,
04:40over to here and now
04:42we have, sorry, not to
04:44there. So here I have
04:46a gradient of zero for
04:47two to here. Now at
04:50two I have a gradient
04:51of two and at four
04:56I have a gradient of
04:57four and it's going to
04:59go up to here, right?
05:00So you can see that
05:03is not by any stretch
05:05of the imagination at great.
05:08is not a great approximation.
05:12Now imagine I did it
05:14with a step length of
05:15one. What happens is it
05:17stays for but only to
05:19here because the step length
05:22is one. Then it's then
05:24degrading to this point is
05:26negative three. So it's going
05:27to be negative three until
05:29there. Then it's going to
05:31be negative two until here.
05:34Then it's going to be
05:34negative one here. Then it's
05:36going
05:36And it'll be zero here.
05:40And it's gonna be one
05:41there. Then it's gonna be
05:43two to here. And it's
05:45gonna be three. And then
05:48it's gonna be four. Now
05:50note, because the step length
05:51is smaller, the approximation was
05:54better. Now it's not a
05:55perfect approximation. But imagine, and
05:57this is actually how your
05:58calculator does a lot of
05:59its calculations. It just goes
06:03smaller and smaller and smaller
06:04smaller. So if this gets,
06:06if my step length is
06:09smaller and smaller and smaller
06:10and smaller, what happens is
06:11this gets closer and closer
06:12and closer to the actual
06:14curve. So that is essentially
06:17what ordered method is doing.
06:21Now, how does all this
06:22relate to the formula? Well,
06:24let's try and figure that
06:25out. Okay, this is the
06:27formula. What we do is
06:30we're going to write it
06:31out like this. It's always
06:31the same.
06:33n is the number of
06:38steps, if you like. So
06:38I'm going to start with
06:39zero. This is my zero
06:40step, my first step, second
06:43step, and third step. Now
06:45the question says, consider the
06:49differential equation dy to x
06:50equals x with y equals
06:51zero and x equals zero.
06:53So it gives me an
06:54initial condition here. And this
06:58is used Euler's method with
06:59step length h equals
07:01one to find an approximate
07:02value of y when x
07:04equals three. So my h
07:06is one, my step length
07:08is one. So I'm going
07:09to do, I'm going to
07:10have x of n here.
07:15The first x, x is
07:17zero if you like, is
07:19going to be this initial
07:20condition here. So this has
07:23to be zero. And then
07:26the step length, the next
07:27one is just whatever the
07:28step length is.
07:29The step length is one,
07:30it's going to have one,
07:31then two, then three. If
07:34this step length was zero
07:35point two, it'll be zero
07:37point two, zero point four,
07:39zero point six, whatever the
07:40case might be. Next one,
07:42we have Y of N.
07:46So my Y of N,
07:47I'm gonna give this more
07:48space, and I'll show you
07:49Y in a second. Y
07:51of N is the Y
07:53value. So we're gonna use
07:54orders method to find an
07:56approximate value
07:57Y when X equals three.
08:00So I want to, what
08:00I'm trying to find is
08:01the Y value here when
08:03X is three. And this
08:04is what I'm trying to
08:05find. But the first Y
08:07value is zero. That is
08:08given. Okay. And then over
08:14here, I'm going to write
08:16F of X and Y.
08:21Now this you see in
08:22the formula here. Now F,
08:24this is important.
08:25f of x and yn
08:30is actually equal to dy
08:34dx. So this is actually
08:37the gradient of the function.
08:39So dy dx is f
08:42of x and yn. Okay,
08:46now what we do is,
08:49let's move that up a
08:50little bit. What we do
08:53is,
08:53We're going to go across.
08:56So when n is 0,
08:59this is the initial condition.
09:01I have my x is
09:020, y is 0, that's
09:03because that was given. And
09:04then f of x and
09:06y, and this is my
09:07dy dx, what is the
09:08gradient of the curve at
09:09this point? Well, the gradient
09:11is just x, so the
09:12gradient is 0. If the
09:16gradient, if it was like
09:18x minus y squared, you
09:20do 0 minus
09:21zero squared, which would also
09:22be zero, but obviously that
09:24changes depending on the initial
09:26condition and it will change
09:27as we go along here.
09:28But you got to look
09:29at this value, normally, yes,
09:31it's a function of x
09:32and y again to repeat
09:34myself. I just wanted to
09:35give you the kind of
09:36most simple example, I think,
09:37to help explain it. Okay,
09:41so zero zero, fine. So
09:44remember guys, you don't, well,
09:47you don't have to remember,
09:48I'm telling you, you don't
09:49don't have to sketch any
09:51of these graphs, I am
09:52just drawing the graph to
09:54kind of help you explain
09:54it. All you need is
09:55to draw this. So what
09:57we're doing is we're assuming
10:00that the gradient, we're going
10:03to start at 0. So
10:04he wants to find an
10:05approximate approximation for x equals
10:073. So the real value
10:10when when x equals 3,
10:12the real value is 3
10:13squared, which is 9 over
10:142, which is 4 .5
10:15or 9 over 2. And
10:16it's here. That's the real
10:17value.
10:17We want to find an
10:18approximation to that. So what
10:20he says is he assumes
10:22we started 0 and we
10:25assume the gradient is 0
10:28for the step length of
10:291. Now how does this
10:33relate to this formula? So
10:37it's like to get to
10:38the next iteration. So these
10:41are iterations. To get to
10:43y of n plus 1
10:45the next y
10:45I get the previous y,
10:48y, then, so which is
10:500. Oops, I get 0
10:53plus h times the derivative.
10:59So it's the step length,
11:02which is 1, and it's
11:041 times the derivative, which
11:06is 0 equals 0. So
11:08essentially what he's done is
11:10he has said, he is
11:12saying, okay,
11:13We're going to start at
11:14zero. We're going to assume
11:16the gradient to zero. And
11:19we're going to add this
11:22gradient of zero one time.
11:25So it's like this. We're
11:26going to go over one.
11:27We're going to start at
11:28zero. And we're going to
11:29go over two one. But
11:34because the gradient is zero,
11:35we're not moving up at
11:36all. If the gradient was
11:38two, we'd say we started
11:39zero. And we'll go up
11:40two times the step length.
11:41here, that would be my
11:42new approximation. But we're starting
11:44at zero, we're going to
11:45go up to zero times
11:46the step length, which is,
11:49um, there. Okay. Next. So
11:57we keep, we keep going
11:58on. What x x n
12:01is one, y n is
12:02zero. What is f of
12:04x and y n? Well,
12:05again, we have to look
12:06at this. This is the
12:08derivative, the derivative of when
12:09x is
12:09one is just one. So
12:12now we go, y of
12:16n plus one, so y
12:17of two is y of
12:19one. Again, that's zero. Plus
12:22one times, because one is
12:24our h, this is our
12:26step length, one times the
12:29derivative, which is one, one
12:31times one, is one. Now
12:33again, if you kind of
12:34think about what I'm saying
12:35here,
12:38I'm talking about here is
12:41we are going up, we're
12:44gonna go up one of
12:45these, we're gonna go across
12:47one and up one. So
12:49for this step length, we're
12:51gonna assume the gradient is
12:53one. So that's why we
12:55have zero plus one times
12:57one, up to here. Okay,
13:01let me go again. What's
13:03the gradient at this point?
13:04Well, it's two.
13:06So now we go Y
13:11of 3, which is Y
13:12of 2. So 1 plus
13:161 times 2, which is
13:223. And again, if I
13:26do this, it means I'm
13:29assuming that the gradient is
13:312 for this
13:34and step length of one,
13:36and I get to here,
13:38and that is my approximation.
13:41So when he says use
13:42Euler's method with step length
13:45h equals one to find
13:46an approximate value of y
13:48when x equals three, it's
13:51this, the approximate value of
13:53y when x equals three
13:55is y equals three. And
13:57you can just leave it
13:58like this, or you can
13:59just say at the end,
14:02approximate value, approximate value of
14:07Y when X equals three
14:13is Y equals three. And
14:16that's it, done. Now as
14:17I say, that was the
14:19simplest example I could possibly
14:20give you. The truth is,
14:22it doesn't actually get a
14:23whole lot more complicated than
14:24that because you're just serving
14:25in values. But I just
14:29wanted to show you one
14:29other thing.
14:30Imagine if the step length
14:34was 0 .5. Now you
14:36can try and do this
14:37example if you want. But
14:39basically what happens is now
14:40instead of going, instead of
14:45going across one every time,
14:46I'm going across half. So
14:48you'll notice you'll get a
14:49better approximation. So here x
14:51and a 0, 0, 0,
14:53that's the same. But now
14:56what happens is it starts
14:57to get
14:58closer and closer to the
15:00actual, well, it gets closer
15:01to the curve than this
15:02one. And if we go
15:03all the way down here,
15:05keep doing the same process,
15:06we actually get an approximation
15:07of 3 .75, which is
15:09clearly better than the three
15:14that we got here. And
15:16if you wanted to try
15:16it with a step value
15:18of, I don't know, 0
15:20.1 or 0 .01, you'd
15:25need a pretty powerful calculator
15:26do it, you probably get
15:28an answer very, very, very
15:29close to the correct answer
15:31of 4 .5. Another thing
15:34to note, final kind of
15:36thing to note, when the
15:38curve is concave up like
15:40this, you'll notice you can
15:42actually see it what's happening
15:44because it's concave up and
15:47you're kind of following the
15:49gradient of the curve like
15:51this, the approximation
15:54that you get will always
15:56be less than the actual
15:58real value. However, if the
16:00curve is concave, concave down
16:02like this, you get the
16:04opposite effect happens. You go
16:09like this, then like this,
16:12and the approximation is actually
16:15higher than the real value,
16:18if that makes sense. Okay,
16:20so look, I'm well aware
16:22that's
16:22that's a tricky concept to
16:26get your head around. When
16:28I do the next lesson,
16:32it'll be more straightforward to
16:34just follow exactly what I'm
16:35doing. I'll also show you
16:37a nice trick on the
16:38calculator to help you do
16:41it pretty easily where you
16:45just program in values into
16:48a spreadsheet. Personally,
16:50and I probably would still
16:52recommend you do it the
16:53long way like this, but
16:55it's certainly good to know
16:56both ways. Okay, that's it.
16:59And I will see you
17:00in the next video.