Numerical Methods -- Solutions to an Ordinary Differential Equation -- Module 6
Index
1. Euler's Method
https://www.youtube.com/watch?v=ukNbG7muKho
Concept
Euler’s method is the simplest numerical method for solving an initial value problem of the form:
It approximates the solution by moving a small step size
Formula
If you know
where
Pros and Cons
-
Pros:
- Very simple to implement.
-
Cons:
- It is only first-order accurate (error is proportional to
); hence, for a given step size , it may not be very accurate. - It may require very small step sizes to achieve acceptable accuracy, increasing computational cost.
- It is only first-order accurate (error is proportional to
Example 1
So let's say we have this equation and it's derivative :
Note that this is an explicit equation, so we need to find out the derivative ourselves.
We need to approximate the value of
So, since this method requires very small step sizes for good accuracy, let's set :
Another of finding the step size would be:
First, let
So if we took
then :
which results in a more precise step size, so we might get a more precise value if we use this step size.
But for consistency with the example in the video, we will use
So here :
So since our equation depends on
So let's create a table first :
n | Actual value | ||
---|---|---|---|
And start off with the initial point P(1,1), where
n | Actual value | ||
---|---|---|---|
0 | 1 | 1 |
Here
So the value of
Now we use the equation :
to predict the values for the next iterations.
We will continue till
So, for
n | Actual value | ||
---|---|---|---|
0 | 1 | 1 | |
1 | 1.1 | 1.2 |
Next, for
n | Actual value | ||
---|---|---|---|
0 | 1 | 1 | |
1 | 1.1 | 1.2 | |
2 | 1.2 | 1.42 | |
3 | 1.3 | ||
4 | 1.4 | ||
5 | 1.5 |
Next, for
n | Actual value | ||
---|---|---|---|
0 | 1 | 1 | |
1 | 1.1 | 1.2 | |
2 | 1.2 | 1.42 | |
3 | 1.3 | 1.66 | |
4 | 1.4 | ||
5 | 1.5 |
Next, for
n | Actual value | ||
---|---|---|---|
0 | 1 | 1 | |
1 | 1.1 | 1.2 | |
2 | 1.2 | 1.42 | |
3 | 1.3 | 1.66 | |
4 | 1.4 | 1.92 | |
5 | 1.5 |
Now, for
n | Actual value | ||
---|---|---|---|
0 | 1 | 1 | |
1 | 1.1 | 1.2 | |
2 | 1.2 | 1.42 | |
3 | 1.3 | 1.66 | |
4 | 1.4 | 1.92 | |
5 | 1.5 | 2.2 |
Now, time to find out the actual values per value of
So we will use the original equation,
So,
n | Actual value | ||
---|---|---|---|
0 | 1 | 1 | 1 |
1 | 1.1 | 1.2 | |
2 | 1.2 | 1.42 | |
3 | 1.3 | 1.66 | |
4 | 1.4 | 1.92 | |
5 | 1.5 | 1.1 |
n | Actual value | ||
---|---|---|---|
0 | 1 | 1 | 1 |
1 | 1.1 | 1.2 | 1.21 |
2 | 1.2 | 1.42 | 1.44 |
3 | 1.3 | 1.66 | 1.69 |
4 | 1.4 | 1.92 | 1.96 |
5 | 1.5 | 2.2 | 2.25 |
So, we get our final approximation of
What is the "actual value" btw?
In the cases of ODEs and not explicit equations, it's used to update the value of
So our final answer will be
Example 2
https://www.youtube.com/watch?v=U8-4HLKtmDM&list=PLU6SqdYcYsfLrTna7UuaVfGZYkNo0cpVC&index=10
Note that this is NOT an explicit equation, but rather an ODE, so we don't need to find out the derivative ourselves.
In this case, the formula becomes :
Since our given
So we are given a starting condition as :
Let's compute till
So the step size will be :
So using that we construct our table:
n | |||
---|---|---|---|
0 | 0 | 1 | 1 |
1 | 0.02 | 1.02 | 1.04 |
2 | 0.04 | 1.04 | 1.08 |
3 | 0.06 | 1.06 | 1.12 |
4 | 0.08 | 1.08 | 1.16 |
5 | 0.1 | 1.11 | 1.21 |
I got the values early on since I made a program to calculate all this
0, 0, 1, 1
1, 0.02, 1.0204, 1.0404
2, 0.04, 1.0416079999999999, 1.081608
3, 0.06, 1.0636401599999998, 1.1236401599999999
4, 0.08, 1.0865129632, 1.1665129632
5, 0.1, 1.110243222464, 1.210243222464
The value of y at x = 0.1 is: 1.110243222464
However I will do some of them by hand to clear up any confusion.
So for
Similarly for
And so on... I assume you can do the rest of the calculations by yourself.
So the final approximation of
And the value in the video was obtained as
2. Runge-Kutta Method (or Euler's Modified Method)
This method is used for 2nd order differential equations.
This is based upon Euler's method by modifying it.
(obtained by using Euler's method)
then, we use this to get :
Example 1:
Let's say we have :
Another ODE, not an explicit equation.
We are given the starting conditions as
And we are asked to find the value of
So if we continue till
Since we will be finding for two
Or for better accuracy we can :
Let's find out which step size leads to more precise answer :
So, at
We will have our table as :
n | |||
---|---|---|---|
0 | 0 | 1 | 1 |
1 | 0.02 | ||
2 | 0.04 | ||
3 | 0.06 | ||
4 | 0.08 | ||
5 | 0.10 |
We see that we can get the required
And $$y_{1} \ = \ 1 \ + \frac{0.02}{2} \ \times [\ (0^2 \ + \ 1) \ + \ (0.02^2 \ + \ 1.02) ]$$
Now at
Now,
n | |||
---|---|---|---|
0 | 0 | 1 | 1 |
1 | 0.02 | 1.020204 | 0.0020204 |
2 | 0.04 | 1.030830282 | 0.0106262816 |
3 | 0.06 | ||
4 | 0.08 | ||
5 | 0.10 |
So we have our as