
m is well approximated by m0 or m1 if
(Backward difference
Implicit Euler - see later)
Solve
Calculate f(x) at t0
f0
Finite difference formula:

! The ODE is in general![]()
! The right hand side function may
! depend on time t explicitly
! as well as implicitly through
! the behaviour of x.Specify initial conditions:
Specify final time tf and step size h.
- time t0
- value of differential variable x0
Initialise counter n = 0 to count steps.
do while tn < tf
! we still have some way to go
set tn+1 = tn + hend do
if tn+1 > tf then! truncate the final step set tn+1 = tfend if
! for the last step only redefine h = tf - tn
evaluate fn = f(xn, tn)
calculate xn+1 = xn + h fn
increment n by 1
return
IC: M0 = 500 kg at t0 = 0 s
Final time:
tf = 100 s
Step size: h = 20 s
| step number | time t (s) | holdup M (kg) |
| 0 | 0 | 500 |
| 1 | 20 | 520 |
| 2 | 40 | 540 |
| 3 | 60 | 560 |
| 4 | 80 | 580 |
| 5 | 100 | 600 |
The numerical solution equals the exact solution because the exact solution is linear.
This statement must be qualified because computers do not work in exact arithmetic. Real numbers are stored in a finite form.
Perhaps 500.00000 + 20.000000 is calculated as 519.999999.
Rounding error accumulates in computer arithmetic because of the finite representation of numbers.
A further consequence of rounding error.
The algorithm contains tests to decide whether
The latter may have unexpected effects if, say,
80 + 20 = 99.99999
The algorithm will execute the loop again after reaching `100' (or as the computer thinks, 99.99999).
It will chop h to 0.00001.
Probably not serious, but output may look odd.
Exact solution is known:
k is a rate constant for decay of x.
Units: (1/seconds).
Parameter values:
k = 1 s-1
IC: x0 = 100
at: t0 = 0 s
final time: tf = 2 s
step size: h = 0.25 s
| step | time (s) | x(Euler) | x(Exact) | abs error |
| 0 | 0.00 | 100.0000 | 100.0000 | 0.0000 |
| 1 | 0.25 | 75.0000 | 77.8801 | 2.8801 |
| 2 | 0.50 | 56.2500 | 60.6531 | 4.4031 |
| 3 | 0.75 | 42.1875 | 47.2367 | 5.0492 |
| 4 | 1.00 | 31.6406 | 36.7879 | 5.1473 |
| 5 | 1.25 | 23.7305 | 28.6505 | 4.9200 |
| 6 | 1.50 | 17.7979 | 22.3130 | 4.5151 |
| 7 | 1.75 | 13.3484 | 17.3774 | 4.0290 |
| 8 | 2.00 | 10.0113 | 13.5335 | 3.5222 |

| step | time (s) | abs error | rel error |
| 0 | 0.00 | 0.0000 | 0.0000 |
| 1 | 0.25 | 2.8801 | 0.0370 |
| 2 | 0.50 | 4.4031 | 0.0726 |
| 3 | 0.75 | 5.0492 | 0.1069 |
| 4 | 1.00 | 5.1473 | 0.1399 |
| 5 | 1.25 | 4.9200 | 0.1717 |
| 6 | 1.50 | 4.5151 | 0.2024 |
| 7 | 1.75 | 4.0290 | 0.2319 |
| 8 | 2.00 | 3.5222 | 0.2603 |
Next - Section 4.4.4: Time Constant, Accuracy
and Step Size
Return to Section 4.4 Index
Return to Section 4 Index
Course Organiser Last modified: Tue Aug 4 15:37:33 BST