Lecture 15 ODEs Part2
Lecture 15 ODEs Part2
Dominated by
Step size required for stability
Condionally stable
<1
For the fast transient part of the example, the step size to maintain stability
must be < 2/1000 = 0.002
An even smaller step size would be required for an accurate solution!
Implicit Euler method:
unconditionally stable
EXAMPLE
Use both the explicit and implicit Euler methods to solve
where y(0) = 0.
(a) Use the explicit Euler with step sizes of 0.0005 and 0.0015 to solve
for y between t = 0 and 0.006.
(b) Use the implicit Euler with a step size of 0.05 to solve for y between
0 and 0.4.
Solution.
(a) The explicit Euler’s method
y1(0) = 52.29
y2(0) = 83.82
Solve simultaneously
MATLAB Functions for Stiff Systems
ode23s: is a one-step solver and may be more efficient than ode15s at crude
tolerances. It can solve some kinds of stiff problems better than ode15s.
Ei 1
1
(5k1 6k2 8k3 9k4 )h k4 f ti 1 , yi 1
72
At each step, the error is compared to a tolerance:
RelTol = 10-3
E max( RelTol y , AbsTol )
AbsTol=10-6
The predictor is the weak link in the method because it has the greatest
error.
Improve Heun’s method by developing a predictor with a local error of
O(h3).
yi01 yi 1 f (ti , yi )2h
Need yi-1: not a typical initial value problem!
yij1 yij11
a j
100%
yi 1
When |εa| is less than an error tolerance εs, the iterations are
terminated
EXAMPLE.
Use the non-self-starting Heun method to integrate
y' = 4e0.8t − 0.5y from t = 0 to 4 with a step size of 1.
Step 2 (i=1):
yi01 yim1 f (ti , yim )2h
The predictor
y20 2 [4e 0.8(1) 0.5(6.36087)]2 13.44346
Better than 12.0826 (εt = 18%) that
Iterations yield 15.76693 (εt = 6.8%) was computed with the original
Heun method
Non-self-starting Heun method: characteristic of most multistep methods.
For n=1,
𝑦𝑖+1 = 𝑦𝑖−1 + 2𝑓𝑖 ℎ
Equivalent to the midpoint method
For n=2,
3ℎ
𝑦𝑖+1 = 𝑦𝑖−2 + 𝑓 + 𝑓𝑖−1
2 𝑖
For n=3,
4ℎ
𝑦𝑖+1 = 𝑦𝑖−3 + 2𝑓𝑖 − 𝑓𝑖−1 + 2𝑓𝑖−2
3
Closed formulas
𝑥𝑖+1
𝑦𝑖+1 = 𝑦𝑖−𝑛+1 + න 𝑓𝑛 𝑥 𝑑𝑥
𝑥𝑖−𝑛 +1
For n=1,
ℎ
𝑦𝑖+1 = 𝑦𝑖 + 𝑓𝑖 + 𝑓𝑖+1
2
which is equivalent to trapezoidal rule.
For n=2,
ℎ
𝑦𝑖+1 = 𝑦𝑖−1 + 𝑓𝑖−1 + 4𝑓𝑖 + 𝑓𝑖+1
3
One way to derive the Adams formulas is to write a forward Taylor series expansion
around xi:
𝑓𝑖′ 2 𝑓𝑖′′ 3
𝑦𝑖+1 = 𝑦𝑖 + 𝑓𝑖 ℎ + ℎ + ℎ +⋯
2 6
𝑓𝑖 −𝑓𝑖−1 𝑓𝑖′′
𝑓𝑖′ = + ℎ +𝑂(ℎ2 )
ℎ 2
This formula is called the second order open Adams formula. Open
Adams formulas are also referred to as Adams-Bashforth formulas.
𝑛−1
The coefficients βk are compiled in the following Table. Notice that the first
order is Euler’s method.
𝑛−1
𝑛−1
One way to derive the Adams formulas is to write a backward Taylor series
expansion around xi+1:
′ ′′
𝑓𝑖+1 2
𝑓𝑖+1
𝑦𝑖+1 = 𝑦𝑖+1 − 𝑓𝑖+1 ℎ + ℎ − ℎ3 + ⋯
2 3
𝑛−1
0 𝑚 4ℎ
𝑦𝑖+1 = 𝑦𝑖−3 + 2𝑓𝑖𝑚 − 𝑓𝑖−1
𝑚 𝑚
+ 2𝑓𝑖−2
3
and the three point Newton-Cotes formula (Simpson’s 1/3 rule) as a
corrector:
𝑗 ℎ 𝑚 𝑗−1
𝑦𝑖+1 = 𝑦𝑖−1 + 𝑓𝑖−1 + 4𝑓𝑖𝑚 + 𝑓𝑖+1
𝑚
3
where j is an index representing the number of iterations of the modifier.
Fourth-Order Adams Method:
0 55 𝑚 59 𝑚 37 𝑚 9 𝑚
𝑦𝑖+1 = 𝑦𝑖𝑚 + ℎ 𝑓𝑖 − 𝑓𝑖−1 + 𝑓𝑖−2 − 𝑓𝑖−3
24 24 24 24
𝑗 9 𝑗−1 19 𝑚 5 𝑚 1 𝑚
𝑦𝑖+1 = 𝑦𝑖𝑚 +ℎ 𝑓 + 𝑓𝑖 − 𝑓𝑖−1 − 𝑓
24 𝑖+1 24 24 24 𝑖−2
Boundary-Value Problems
For an nth order equation, n conditions are required. If all the conditions
are specified at the same value of the independent variable, then we are
dealing with an initial value problem.
In contrast, there is another application for which the conditions are not
known at a single point, but rather, are known at different values of the
independent variable. Because these values are often specified at the
extreme points or boundaries of a system, they are customarily referred to
as boundary value problems.
The Shooting Method
The shooting method is based on converting the boundary value
problem into an equivalent initial value problem.
Use the shooting method to solve for a 10 m rod with h = 0.01 m-2, Ta =
20 and the boundary conditions
the second-order equation can be expressed as two first order ODEs:
and
An M-file
function yp = vanderpol(t,y,mu)
yp = [y(2);mu*(1-y(1)^2)*y(2)-y(1)]; μ is passed as a parameter
Sharper edges:
a visual manifestation of the “stiffness”
of the solution
EXAMPLE.
dx dv c
ODEs v g d vv
dt dt m
Assume that the jumper is initially located 200 m above the ground
and the initial velocity is 20 m/s in the upward direction.
That is,