Euler’s Method of Solving ODEs: Applications
|
In this segment, we’ll talk
about Euler’s method of solving ordinary differential equations, we’ll look
at an example. So, the example we’re asked to
look at is this first order ordinary differential equation right here. We're asked
to calculate the value of y at 3 when y sub 0 is already given to us as 5 and
we'll take a step size of take a step size of 1.5, which simply implies that
we’ll take two steps in order to do this particular problem. So, let's go
through the two steps and see what we get as the value of y at x equal to
three. So, the differential equation is
given in this format here, and what we have to do is try to rewrite it in the
format which is needed for Euler's method and that is this format. And that's
what gives us the function f here; slope is equal
to some function f of x and y, and of course subject to y sub 0 equal to 5.
So, let's go ahead and apply the Euler's method formula. The general formula
is given as this, where h is the step size and let's choose i equal to zero. So, if we choose i
equal to zero, I get y one is equal to y naught plus the value of the
function f at x naught comma y naught times h. So, this is what you do, is to
think about the steps and you'll be all right. X naught is equal to 0 because
that's what the initial condition is given y naught is 5, that's the value of
the y at this value of x, and then h is given to us as 1.5. So, all we have
to do is say y 1 is equal to 5 plus the value of the function at 0 comma 5 so
having said that what is the value of the function at 0 comma 5 times the h
value which is 1.5. So, having said that, you have to substitute x equal to 0
and y equal to 5 there, so let’s see what we get. And this one gives you 5
plus 1 times 1.5, and that is 6.5. So, 6.5 is the value of y1, which is the approximate
y at 1.5 because the step size is, x1 is x naught plus h right, so x naught
is zero and h is 1.5 so it’s 1.5. So, that's where we are finding out
whatever value of y is, but that’s not what we’re after. We're after the y value of y at
x equal to 3, so that means that we have to take one more step. Please don't
call it one more iteration, because we are not refining the value, we are
going a step ahead from 0 to 1.5, and the next step will go from 1.5 to 3.
So, if I use i equal to 1 now, I’ll get y2 is equal
to y1 plus the value of the function at x1 comma y1 times h. And what is the
value of, let's write down x1, we just said is 1.5, the corresponding value
of y at that particular point will now be 6.5, and of course our h is still
1.5. Let's go and calculate what x 2 is. X 2 is nothing but x 1 plus h so, so
it would be 1.5 plus 1.5, that gives you 3. So, when we calculate the value
of y 2, it will be in fact, the approximate value of y at x equal to 3. So, we
get y2 is equal to what is y1, it is 6.5, plus the value of the function
calculated at 1.5 comma 6.5, times the step size, 1.5. So, what we have is
what is the value of the function at these two values 3 e to the power minus
1.5, minus 0.4 times the value of y which is 6.5,
times 1.5, so this gives me 6.5 plus minus 1.93061 times 1.5, and this value
here turns out to be 3.604. So, this is the approximate value of y at x2
which we know that x2 is 3, and that's what we're after. So, y sub 3 is approximately
equal to 3.604, y sub 3 can be found exactly to be 2.763, that is the exact
value guys. And in the description of this YouTube video, you will find a
link to how I found 2.763, quite a number of students ask me that question,
how did I get 2.763? And then if you want to calculate your relative true
error, in this case, it will turn out to be 30.44 percent. The relative true
error is the difference, is the relative difference, between the approximate
value and the exact value. So, what you’re finding out is that, even a step
size of 1.5 gives you a very large relative true error. So, one way of doing
this is to decrease the step size, and of course that will take more time to
do it by hand, but you can try to write a computer program and see that if
you can see that when you reduce the step size, that you get your relative
two errors reduced, and that is the end of this segment. |