Euler's Method: Example




Uploaded by numericalmethodsguy on 11.02.2009

Transcript:
.
.
In this segment, we're going to take an example of Euler's method.
So Euler's method is the first
method which people talk about when they are solving ordinary differential equations.
So let's go ahead and take an example here.|So somebody gives us a differential equation of dy by dx,
plus 0.4 y is equal to 3 e to the power
minus x, and y of 0 is given as 5,
and what they are asking you to do is to calculate the value of y, let's suppose,
at 3.|Because eventually, what you are trying to do is
when you are solving a differential equation is to solve the dependent variable, in this case being y,
as a function of x.|So in this, because we're talking numerical methods, you'll be asked to calculate
the value of the dependent variable, y, at some point of x, or some points of x.
So to keep it simple, we're just seeking the value of y at x equal to 3.
Now, let's go ahead and, in the first case choose h equal to . . .
h equal to 3, which means that the step size is h equal to three.|That means I'll be taking one step, because
I'm at 0, the value is given to me as 5, so when I choose h equal to 3, I'll be
directly be able to then able to get what the value of y at x equal to 3 is.
The first step, of course, when you are looking at a differential equation, you have to rewrite it in the form
where you are able to write down dy by dx in the form of f of x, comma, y,
and in this case, it will be just 3 e to the power minus x, minus 0.4 y.
You're going to simply take 0.4 y to the right-hand side,
and you'll be able to write it in this particular form, so that's what your function of x, comma, y is.
So if I want to write it separately, what this function, f, is, which is my
slope, and if I know values of x and y, I can calculate the
value of the slope of the dependent variable with respect to the independent variable, which is . . .
which is x.|In this case, since we are choosing a step size of h equal to 3, let's go ahead and see
what do we get?|Now, the Euler's method formula is given as this,
y-sub-i-plus-1 is equal to yi, plus the value of the function at xi,
yi, times h, and if I choose i equal to 0,
I get y1 is equal to y0,
plus f of x0, comma, y0, times h.
Now, I already know that, hey, what do I have for x0?|For x0 I have
0, the value of y0 is simply the value of y
at this x0, which is 3 . . . which is, sorry, 5, that's the
boundary condition which is given to me, and then, of course, I need to know
what the value of h is, I need to know what the value of h is, and h is
3, because that's something which I am choosing.|So from here, I'll get y1
is equal to y0, which is 5, plus the value of the function at x0, which is 0,
the value of y0 is 5, times the value of h, which is 3,
and that gives me 5, plus, what is the value of the function at 0, comma, 5?
The function is 3 e to the power minus x, so x is 0,
minus 0.4 times y, which is 5,
times 3.|So that gives me 5, plus 3
minus 2, times 3, and that gives me 5, plus
1 times 3, and that gives me 8.
So that's the value of y1 which I am getting, but what is y1?|y1 is nothing but the value
of the function at x1, so y is the approximate value of y at x1,
and what is x1?|x1 is nothing but the value of x0 plus h, where h is
the step size, x0 is 0, h is 3, so that's y of 3.
So this value 8 here is nothing but the approximate value
of y at x equal to 3.|So let me just write it down here, that
y at x equal to 3, which is same as y1,
is approximately . . . maybe I should just say, is approximately
now equal to 8, and this is what I get by using the step size of
h equal to 3.|Now, if you're going to look at the true value,
y at x equal to 3, the true value is 2.763,
that is the true value.
And you can find the true value as part of your homework, by going back to your ordinary differential
equation course fundamentals, whether you're going to use the classical solution technique of finding the homogenous
part and the particular part, or you're going to use Laplace transforms, or separation by
parts, that's something of your choosing.|Go ahead and verify for yourself
the exact value of the . . . of the y at x equal to 3 is
2.763, and you can very well see that the true error is pretty huge here.|It is exact value,
2.763 minus 8, which turns out to be -5.237,
and if I was going to look at the relative true error, that turns out to
be about to be about 190 percent.
So the question arises, how do I go about making this
true error to be smaller?|The simple fact is that you can just make
h to be a smaller number, let's suppose if I choose h equal to 1.5.
Now, if I am at 0, that's where my initial condition is given, in one step
I will be able to go to 1.5, in the next step I will be able to go to 3.0, so it'll take me
two steps to be able to find out the value of y at x equal to 3.
So let's go ahead and pursue that.|So the way to pursue that is
by saying i is equal to 0, so I get y1 is equal to y0, plus the value
of the function at x0, comma, y0, times h.
x0 is 0, y0 is 5,
and h is now 1.5.|So I get y1
is equal to y0, which is 5, plus the value of the function at 0
and 1.5, times h, which is now
1.5 . . . no, that's not right, it'll be the value of the
function at x0, comma, y0, x0 is 0, and y0 is 5.
So I get 5, plus, what is the value of the function at 0, comma, 5?|What is the
value at . . . value of the function is 3 e to the power minus x, which is -0,
minus 0.4 times the value of the function at
x0, which is 5, times 1.5.|So this turns out to be 5,
plus 1 times 1.5,
and that value turns out to be 6.5.|So what you've got
to understand is that this is now the value of y1, which is
same as saying that it's the value of y at x0 plus h,
x0 is 0, h is 1.5, and that's 1.5.
So this 6.5 which you're obtaining is the intermediate value on
our way to finding out the value at 3, but this is the value at 1.5.|So I'm
going to use that now to calculate our value of y at . . .
y at 3.|So let's go ahead and do that here.|What we have now is that
i is equal to 1, so y2 will be equal to y1, plus the
value of the function at x1, comma, y1, times h, because I'm choosing
i to be equal to 1.|Now, from the previous thing, I know that x1 is 1.5,
and the corresponding value of y which you obtained at that particular point is 6.5,
and, of course, h we already know is 1.5.
So we know everything which we need to know for calculating the value of y2.
So y2 is y1, which is 6.5, plus the value of the function now at
x, the new x, which is 1.5, and the corresponding value of y, which is 6.5.
Now, keep in mind this value of 6.5 is an approximate value of y at 1.5, not
the exact value, so the slope which you are going to calculate will also be approximate,
it won't be exact.|So you can see that how the error gets propagated from
one step to another.|Not only do you have the error associated with the formula itself, but also
with the value of y which you are putting in here.
So you get 6.5, plus, what is the function?|It is 3 e to the power minus x, so it's -1.5,
minus 0.4 y, which is 6.5,
times 1.5.|And here I get 6.5, plus,
this value turns out to be -1.93061,
times 1.5, and this value here turns out
to be equal to 3.604.
And that is the approximate value at y
at x2, which is nothing but the value at 3 which you are seeking.
So you're getting 2.604 now, as the value there.|And you can very well
see that the true error associated with this is, the exact value is
2.763, the approximate value is
3.604, which we just obtained, so the true error in this case is
-0.841,
and the corresponding relative true error, approximately, is now
30.44 percent.|So what you are finding out is by choosing h to be
a smaller number now, what you are getting is that you're getting the true error . . . a smaller value of
true error, and the relative true error is also decreasing to 30.|It was 190
percent for h equal to 3, and now it's 30 percent for h equal to
1.5.|So if you keep on decreasing the step size, you'll find out that you get a better and better approximation
for your value of y.|And that's the end of this segment.
.
.
.
.