Math 4B Euler Method

Math 4B
Euler’s Method
http://www.youtube.com/watch?v=07HCb0eR9iY
Prepared by Vince Zaccone
For Campus Learning
Assistance Services at UCSB
Euler’s Method will find an approximate solution to an initial value problem.
Let’s work through a simple example:
Suppose we want to solve the following initial value problem:
a)
First find an estimate for y(2) using Euler’s Method
with a step size of 1
b)
Next get a better estimate by using a step size of 0.5.
c)
Finally, solve the problem exactly and compare to the
estimates from parts a) and b)
y  0.3  y
y(0)  1
Prepared by Vince Zaccone
For Campus Learning
Assistance Services at UCSB
Euler’s Method will find an approximate solution to an initial value problem.
Let’s work through a simple example:
Suppose we want to solve the following initial value problem:
a)
First find an estimate for y(2) using Euler’s Method
with a step size of 1
b)
Next get a better estimate by using a step size of 0.5.
c)
Finally, solve the problem exactly and compare to the
estimates from parts a) and b)
y  0.3  y
y(0)  1
Euler’s method will create a piecewise linear approximation to y(t) by using
the given differential equation to calculate the slope of the solution curve at
each step, then following that slope to calculate the approximations.
Prepared by Vince Zaccone
For Campus Learning
Assistance Services at UCSB
Euler’s Method will find an approximate solution to an initial value problem.
Let’s work through a simple example:
Suppose we want to solve the following initial value problem:
a)
First find an estimate for y(2) using Euler’s Method
with a step size of 1
b)
Next get a better estimate by using a step size of 0.5.
c)
Finally, solve the problem exactly and compare to the
estimates from parts a) and b)
y  0.3  y
y(0)  1
The first step is to use the given equation and initial value to find the initial slope (at t=0):
y(0)  0.3  y(0)  0.3  (1)  0.3
Prepared by Vince Zaccone
For Campus Learning
Assistance Services at UCSB
Euler’s Method will find an approximate solution to an initial value problem.
Let’s work through a simple example:
Suppose we want to solve the following initial value problem:
a)
First find an estimate for y(2) using Euler’s Method
with a step size of 1
b)
Next get a better estimate by using a step size of 0.5.
c)
Finally, solve the problem exactly and compare to the
estimates from parts a) and b)
y  0.3  y
y(0)  1
The first step is to use the given equation and initial value to find the initial slope (at t=0):
y(0)  0.3  y(0)  0.3  (1)  0.3
Next we use this slope to find the approximation for y(1):
~
y(1)  y(0)  y(0)  t
~
y(1)  1  (0.3)  (1)  1.3
Prepared by Vince Zaccone
For Campus Learning
Assistance Services at UCSB
Euler’s Method will find an approximate solution to an initial value problem.
Let’s work through a simple example:
Suppose we want to solve the following initial value problem:
a)
First find an estimate for y(2) using Euler’s Method
with a step size of 1
b)
Next get a better estimate by using a step size of 0.5.
c)
Finally, solve the problem exactly and compare to the
estimates from parts a) and b)
y  0.3  y
y(0)  1
The first step is to use the given equation and initial value to find the initial slope (at t=0):
y(0)  0.3  y(0)  0.3  (1)  0.3
Next we use this slope to find the approximation for y(1):
~
y(1)  y(0)  y(0)  t
~
y(1)  1  (0.3)  (1)  1.3
Now we repeat this process, calculating the slope at t=1:
~
y(1)  (0.3)  ~
y(1)  (0.3)  (1.3)  0.39
Prepared by Vince Zaccone
For Campus Learning
Assistance Services at UCSB
Euler’s Method will find an approximate solution to an initial value problem.
Let’s work through a simple example:
Suppose we want to solve the following initial value problem:
a)
First find an estimate for y(2) using Euler’s Method
with a step size of 1
b)
Next get a better estimate by using a step size of 0.5.
c)
Finally, solve the problem exactly and compare to the
estimates from parts a) and b)
y  0.3  y
y(0)  1
The first step is to use the given equation and initial value to find the initial slope (at t=0):
y(0)  0.3  y(0)  0.3  (1)  0.3
Next we use this slope to find the approximation for y(1):
~
y(1)  y(0)  y(0)  t
~
y(1)  1  (0.3)  (1)  1.3
Now we repeat this process, calculating the slope at t=1:
~
y(1)  (0.3)  ~
y(1)  (0.3)  (1.3)  0.39
We have one last step – calculate the approximation for y(2):
~
y(2)  ~
y(1)  ~
y(1)  t
~
Here is our answer to part a)
y(2)  1.3  (0.39)  (1)  1.69
Prepared by Vince Zaccone
For Campus Learning
Assistance Services at UCSB
It is helpful to see a graph of our results.
y(step size 1)
2
1.8
1.6
1.4
1.2
1
0.8
0.6
0.4
0.2
0
Slope=0.39
Slope=0.3
0
0.5
1
1.5
2
Notice that we used two steps, and we have two straight line segments
(whose slopes we calculated from the given D.E.)
Prepared by Vince Zaccone
For Campus Learning
Assistance Services at UCSB
Now we can run through the procedure for part b). We use 4 steps this time, each of step size 0.5.
This time let’s make a table to organize our calculations:
t
0.0
y
y’
1.0
0.5
1.0
1.5
2.0
Prepared by Vince Zaccone
For Campus Learning
Assistance Services at UCSB
Now we can run through the procedure for part b). We use 4 steps this time, each of step size 0.5.
This time let’s make a table to organize our calculations:
t
y
y’
Calculate y’(0) from the original D.E.
y  0.3  y
0.0
1.0
0.5
1.0
1.5
2.0
Prepared by Vince Zaccone
For Campus Learning
Assistance Services at UCSB
Now we can run through the procedure for part b). We use 4 steps this time, each of step size 0.5.
This time let’s make a table to organize our calculations:
t
y’
y
Calculate y’(0) from the original D.E.
y  0.3  y
0.0
1.0
0.3
0.5
1.0
1.5
2.0
Prepared by Vince Zaccone
For Campus Learning
Assistance Services at UCSB
Now we can run through the procedure for part b). We use 4 steps this time, each of step size 0.5.
This time let’s make a table to organize our calculations:
t
0.0
y’
y
1.0
0.3
Find y(0.5) from the formula
0.5
~
y(0.5)  y(0)  y(0)  t
1.0
1.5
2.0
Prepared by Vince Zaccone
For Campus Learning
Assistance Services at UCSB
Now we can run through the procedure for part b). We use 4 steps this time, each of step size 0.5.
This time let’s make a table to organize our calculations:
t
0.0
y’
y
1.0
0.3
Find y(0.5) from the formula
0.5
1.15
~
y(0.5)  y(0)  y(0)  t
~
y(0.5)  1  (0.3)  (0.5)  1.15
1.0
1.5
2.0
Prepared by Vince Zaccone
For Campus Learning
Assistance Services at UCSB
Now we can run through the procedure for part b). We use 4 steps this time, each of step size 0.5.
This time let’s make a table to organize our calculations:
t
0.0
y’
y
1.0
0.3
Calculate y’(0.5) from the original D.E.
0.5
1.15
y  0.3  y
1.0
1.5
2.0
Prepared by Vince Zaccone
For Campus Learning
Assistance Services at UCSB
Now we can run through the procedure for part b). We use 4 steps this time, each of step size 0.5.
This time let’s make a table to organize our calculations:
t
0.0
y’
y
1.0
0.3
Calculate y’(0.5) from the original D.E.
0.5
1.15
0.345
y  (0.3)  (1.15 )  0.345
1.0
1.5
2.0
Prepared by Vince Zaccone
For Campus Learning
Assistance Services at UCSB
Now we can run through the procedure for part b). We use 4 steps this time, each of step size 0.5.
This time let’s make a table to organize our calculations:
t
y’
y
0.0
1.0
0.3
0.5
1.15
0.345
1.0
Find y(1.0) from the formula
~
y(1.0)  ~
y(0.5)  ~
y(0.5)  t
1.5
2.0
Prepared by Vince Zaccone
For Campus Learning
Assistance Services at UCSB
Now we can run through the procedure for part b). We use 4 steps this time, each of step size 0.5.
This time let’s make a table to organize our calculations:
t
y’
y
0.0
1.0
0.3
0.5
1.15
0.345
1.0
1.5
1.3225
Find y(1.0) from the formula
~
y(1.0)  ~
y(0.5)  ~
y(0.5)  t
~
y(1.0)  1.15  (0.345)  (0.5)
~
y(1.0)  1.3225
2.0
Prepared by Vince Zaccone
For Campus Learning
Assistance Services at UCSB
Now we can run through the procedure for part b). We use 4 steps this time, each of step size 0.5.
This time let’s make a table to organize our calculations:
t
y’
y
0.0
1.0
0.3
0.5
1.15
0.345
1.0
1.3225
Fill in the rest of the table in the same
manner, calculating a slope, then
using it to get the next value for y…
1.5
2.0
Prepared by Vince Zaccone
For Campus Learning
Assistance Services at UCSB
Now we can run through the procedure for part b). We use 4 steps this time, each of step size 0.5.
This time let’s make a table to organize our calculations:
t
y’
y
0.0
1.0
0.3
0.5
1.15
0.345
1.0
1.3225
1.5
1.520875
0.39675
Fill in the rest of the table in the same
manner, calculating a slope, then
using it to get the next value for y…
I kept all the digits, but you can
probably round off a little bit
2.0
Prepared by Vince Zaccone
For Campus Learning
Assistance Services at UCSB
Now we can run through the procedure for part b). We use 4 steps this time, each of step size 0.5.
This time let’s make a table to organize our calculations:
t
y’
y
0.0
1.0
0.3
0.5
1.15
0.345
1.0
1.3225
0.39675
1.5
1.520875
0.4562625
2.0
1.74900625
Fill in the rest of the table in the same
manner, calculating a slope, then
using it to get the next value for y…
I kept all the digits, but you can
probably round off a little bit
Here is our answer to part b)
Prepared by Vince Zaccone
For Campus Learning
Assistance Services at UCSB
Here is the graph of our results from parts a) and b).
y(step size 1)
y(step size 0.5)
2
1.8
1.6
1.4
1.2
1
0.8
0.6
0.4
0.2
0
2, 1.749
2, 1.69
0
0.5
1
1.5
2
The new calculation should be more accurate because we used more steps
that were closer together. In the next step we will find the exact answer.
Prepared by Vince Zaccone
For Campus Learning
Assistance Services at UCSB
We can actually solve this problem, so let’s do it using separation of variables.
(You should be able to find the general solution to this one in your head in <5 seconds, btw).
y  0.3  y
y(0)  1
We want the value for y(2).
First we will separate, then integrate to find the general solution.
dy
dy
 0 .3  y  
  0.3dt
dt
y
Prepared by Vince Zaccone
For Campus Learning
Assistance Services at UCSB
We can actually solve this problem, so let’s do it using separation of variables.
(You should be able to find the general solution to this one in your head in <5 seconds, btw).
y  0.3  y
y(0)  1
We want the value for y(2).
First we will separate, then integrate to find the general solution.
dy
dy
 0 .3  y  
  0.3dt
dt
y
ln y  0.3  t  C  y  Ce0.3t
Prepared by Vince Zaccone
For Campus Learning
Assistance Services at UCSB
We can actually solve this problem, so let’s do it using separation of variables.
(You should be able to find the general solution to this one in your head in <5 seconds, btw).
y  0.3  y
y(0)  1
We want the value for y(2).
First we will separate, then integrate to find the general solution.
dy
dy
 0 .3  y  
  0.3dt
dt
y
ln y  0.3  t  C  y  Ce0.3t
Next put in the given initial value to find C:
Prepared by Vince Zaccone
For Campus Learning
Assistance Services at UCSB
We can actually solve this problem, so let’s do it using separation of variables.
(You should be able to find the general solution to this one in your head in <5 seconds, btw).
y  0.3  y
y(0)  1
We want the value for y(2).
First we will separate, then integrate to find the general solution.
dy
dy
 0 .3  y  
  0.3dt
dt
y
ln y  0.3  t  C  y  Ce0.3t
Next put in the given initial value to find C:
y(0)  Ce0.3(0)  1  Ce0  C  1
Prepared by Vince Zaccone
For Campus Learning
Assistance Services at UCSB
We can actually solve this problem, so let’s do it using separation of variables.
(You should be able to find the general solution to this one in your head in <5 seconds, btw).
y  0.3  y
y(0)  1
We want the value for y(2).
First we will separate, then integrate to find the general solution.
dy
dy
 0 .3  y  
  0.3dt
dt
y
ln y  0.3  t  C  y  Ce0.3t
Next put in the given initial value to find C:
y(0)  Ce0.3(0)  1  Ce0  C  1
So our solution is
y( t )  e0.3t
Prepared by Vince Zaccone
For Campus Learning
Assistance Services at UCSB
We can actually solve this problem, so let’s do it using separation of variables.
(You should be able to find the general solution to this one in your head in <5 seconds, btw).
y  0.3  y
y(0)  1
We want the value for y(2).
First we will separate, then integrate to find the general solution.
dy
dy
 0 .3  y  
  0.3dt
dt
y
ln y  0.3  t  C  y  Ce0.3t
Next put in the given initial value to find C:
y(0)  Ce0.3(0)  1  Ce0  C  1
So our solution is
y( t )  e0.3t
Last step – plug in t=2
y(2)  e0.6  1.82212
Prepared by Vince Zaccone
For Campus Learning
Assistance Services at UCSB
Here is the graph comparing our results.
2
1.8
1.6
1.4
y(2)
%
error
step size
=1
1.690
7.2%
1.749
4.0%
0.6
step size
=0.5
0.4
exact
1.822
0.0%
1.2
y(step size 1)
1
y(step size 0.5)
0.8
y=e^(0.3t)
0.2
0
0
1
2
3
Notice that the approximation with the smaller step size is closer to the exact value
(but it took more work to get there).
We can calculate the % error in our estimates as a check on theirPrepared
accuracy.
by Vince Zaccone
For Campus Learning
Assistance Services at UCSB