Sei sulla pagina 1di 29

Differential Equations

Lecture 4 Nonhomogeneous and Nonlinear Systems of


First-Order ODEs. Numerical methods for ODEs.
Matylda Jaboska-sabuka
matylda.jablonska-sabuka@lut.fi
Lappeenranta University of Technology
Department of Mathematics and Physics

29 January 2014

Lecture 4 Nonhomogeneous and Nonlinear Systems


Numerical methods for ODEs

Nonhomogeneous and Nonlinear Systems of First-Order ODEs


Method of undetermined coefficients
Method of variation of parameters
Linearization of nonlinear systems

Numerical methods for ODEs


Methods for first-order ODEs
Methods for systems and higher-order ODEs

Matylda Jaboska-Sabuka

Differential Equations 2014

Lecture 4 Nonhomogeneous and Nonlinear Systems


Numerical methods for ODEs

Methods of undetermined coefficients


Method of variation of parameters
Nonlinear ODEs and systems of ODEs

Nonhomogeneous linear system of ODEs


y0 = Ay + g
where the vector g(t) is not identically zero. From a general solution
y(h) (t) of the homogeneous system y0 = Ay and a particular solution
y(p) (t) we get a solution of
y = y(h) + y(p) .
y is called a general solution of (1).

Matylda Jaboska-Sabuka

Differential Equations 2014

(1)

Lecture 4 Nonhomogeneous and Nonlinear Systems


Numerical methods for ODEs

Methods of undetermined coefficients


Method of variation of parameters
Nonlinear ODEs and systems of ODEs

Method of undetermined coefficients


The general rules follow single ODE cases
The modification rule contains vectors of constants, that is for
example if the particular solution is
y(p) = ue t
then u is a vector.
Example 1
Solve
y0 = Ay + g =

3 1
1 3

Matylda Jaboska-Sabuka


y+

6
2

e 2t

Differential Equations 2014

Lecture 4 Nonhomogeneous and Nonlinear Systems


Numerical methods for ODEs

Methods of undetermined coefficients


Method of variation of parameters
Nonlinear ODEs and systems of ODEs

Method of variation of parameters


The general solution of a homogeneous system with two bases can be
written as
"
#

(1)
(2)
y
y
c1
(h)
1
1
y =
= Y(t)c
(1)
(2)
c2
y2
y2
hence, the particular solution is
y(p) = Y(t)u(t).
Substitution into y0 = Ay + g gives
Y0 u + Yu0 = AYu + g
But since Y0 = AY then Yu0 = g and thus u0 = Y1 g.

Matylda Jaboska-Sabuka

Differential Equations 2014

Lecture 4 Nonhomogeneous and Nonlinear Systems


Numerical methods for ODEs

Methods of undetermined coefficients


Method of variation of parameters
Nonlinear ODEs and systems of ODEs

Example 2
Solve by variation of parameters




3 1
6
0
y = Ay + g =
y+
e 2t
1 3
2

Matylda Jaboska-Sabuka

Differential Equations 2014

Methods of undetermined coefficients


Method of variation of parameters
Nonlinear ODEs and systems of ODEs

Lecture 4 Nonhomogeneous and Nonlinear Systems


Numerical methods for ODEs

Nonlinear ODEs and systems of ODEs


Nonlinear ODEs and systems of ODEs

How to analyze the kind and stability properties of critical points of


nonlinear systems?
y0 = f(y), thus

y10 = f1 (y1 , y2 )
y20 = f2 (y1 , y2 )

How to solve nonlinear equations?


00 + k sin = 0

Matylda Jaboska-Sabuka

Differential Equations 2014

Methods of undetermined coefficients


Method of variation of parameters
Nonlinear ODEs and systems of ODEs

Lecture 4 Nonhomogeneous and Nonlinear Systems


Numerical methods for ODEs

This can be done through linearization.


Taylor series
f (a) =

X
f (n) (a)
n=0

12

n!

(x a)n

function y=exp(x)
1degree Taylor

10

3degree Taylor
5degree Taylor

7degree Taylor

6
4
2
0

2.5

1.5

0.5

Matylda Jaboska-Sabuka

0.5

1.5

Differential Equations 2014

2.5

Lecture 4 Nonhomogeneous and Nonlinear Systems


Numerical methods for ODEs

Methods of undetermined coefficients


Method of variation of parameters
Nonlinear ODEs and systems of ODEs

Linearization
For nonlinear systems of first-order ODEs, express y0 as
y0 = f(y) = Ay + h(y) and drop h(y).
For nonlinear higher order equations, transform is into a system of
first-order ODEs and proceed as above.

Matylda Jaboska-Sabuka

Differential Equations 2014

Lecture 4 Nonhomogeneous and Nonlinear Systems


Numerical methods for ODEs

Methods of undetermined coefficients


Method of variation of parameters
Nonlinear ODEs and systems of ODEs

Example 3
y10 = y2
y20 = k sin y1

Matylda Jaboska-Sabuka

Differential Equations 2014

Lecture 4 Nonhomogeneous and Nonlinear Systems


Numerical methods for ODEs

Methods of undetermined coefficients


Method of variation of parameters
Nonlinear ODEs and systems of ODEs

Consequence of linearization

y1 original
y1 linearized
y2 original
y2 linearized

0.8
0.6
0.4
0.2
0
0.2
0.4
0.6
0.8
1

Matylda Jaboska-Sabuka

10

12

14

16

Differential Equations 2014

18

20

Lecture 4 Nonhomogeneous and Nonlinear Systems


Numerical methods for ODEs

Methods for first-order ODEs


Methods for Systems and Higher-order ODEs

Lecture 4 Nonhomogeneous and Nonlinear Systems


Methods of undetermined coefficients
Method of variation of parameters
Nonlinear ODEs and systems of ODEs

Numerical methods for ODEs


Methods for first-order ODEs
Methods for Systems and Higher-order ODEs

Matylda Jaboska-Sabuka

Differential Equations 2014

Lecture 4 Nonhomogeneous and Nonlinear Systems


Numerical methods for ODEs

Methods for first-order ODEs


Methods for Systems and Higher-order ODEs

Step-by-step methods
For initial value problem
y 0 = f (x, y ), y (x0 ) = y0
Method of computing approximate numeric values of the solution y (x) at
the equidistant points on the x-axis
x1 = x0 + h, x2 = x0 + 2h, x3 = x0 + 3h, . . .
where the step size h is a fixed number, for instance, 0.2 or 0.1 or 0.01.
Such formulas are suggested by the Taylor series
y (x + h) = y (x) + hy 0 (x) +

Matylda Jaboska-Sabuka

h2 00
y (x) + . . .
2

Differential Equations 2014

Lecture 4 Nonhomogeneous and Nonlinear Systems


Numerical methods for ODEs

Methods for first-order ODEs


Methods for Systems and Higher-order ODEs

For a small h the higher powers h2 , h3 , . . . are very small. This suggests
the crude approximation
y (x + h) y (x) + hy 0 (x) = y (x) + hf (x, y ).
Euler (or Euler-Cauchy) method
In an iterative way we get the approximation
y1

y0 + hf (x0 , y0 )

...
yn+1

yn + hf (xn , yn )

Geometrically it is an approximation of the curve y (x) by a polygon,


whose first side is tangent to this curve at x0 .
Matylda Jaboska-Sabuka

Differential Equations 2014

Lecture 4 Nonhomogeneous and Nonlinear Systems


Numerical methods for ODEs

Methods for first-order ODEs


Methods for Systems and Higher-order ODEs

Example 4
Apply the Euler method to the following initial value problem, choosing
h = 0.2 and computing y1 , . . . , y5 :
y 0 = y + x, y (0) = 0.
Compare the results with functions real values:
y (x) = e x x 1

Matylda Jaboska-Sabuka

Differential Equations 2014

Lecture 4 Nonhomogeneous and Nonlinear Systems


Numerical methods for ODEs

Methods for first-order ODEs


Methods for Systems and Higher-order ODEs

Euler method
yn+1 = yn + hf (xn , yn )
n
0
1
2
3
4
5

xn
0
0.2
0.4
0.6
0.8
1.0

yn
0
0
0.04
0.128
0.274
0.489

hf (xn + yn )
0
0.2(0.2+0)
0.2(0.4+0.04)
0.2(0.6+0.128)
0.2(0.8+0.274)

Matylda Jaboska-Sabuka

ex x 1
0
0.0214
0.0918
0.2221
0.4255
0.7183

Differential Equations 2014

Lecture 4 Nonhomogeneous and Nonlinear Systems


Numerical methods for ODEs

Methods for first-order ODEs


Methods for Systems and Higher-order ODEs

Automatic variable step size selection


Modern numeric software automatically selects variable step sizes hn , so
that the error of the solution will not exceed a given maximum size TOL.
Now for the Euler method, when the step size is h = hn , the local error at
xn is about 21 hn2 |y 00 (xn )|. We require that this be equal to a given
tolerance TOL,
s
2TOL
1 2 00
hn |y (xn )| = TOL, thus hn =
.
2
|y 00 (xn )|

Matylda Jaboska-Sabuka

Differential Equations 2014

Lecture 4 Nonhomogeneous and Nonlinear Systems


Numerical methods for ODEs

Methods for first-order ODEs


Methods for Systems and Higher-order ODEs

Improved Euler Method (Heuns Method)


In the improved Euler method, in each step we compute first the auxiliary
value

yn+1
= yn + hf (xn , yn )
and then the new value
1

yn+1 = yn + h[f (xn , yn ) + f (xn+1 , yn+1


)]
2
It is a predictor-corrector method.

Matylda Jaboska-Sabuka

Differential Equations 2014

Lecture 4 Nonhomogeneous and Nonlinear Systems


Numerical methods for ODEs

Methods for first-order ODEs


Methods for Systems and Higher-order ODEs

Algorithm for Improved Euler Method


ALGORITHM EULER (f , x0 , y0 , h, n)
For n = 0, 1, . . . , n 1 do
xn+1 = xn + h
k1 = hf (xn , yn )
k2 = hf (xn+1 , yn + k1 )
yn+1 = yn + 21 (k1 + k2 )
OUTPUT: xn+1 , yn+1
End
Stop

Matylda Jaboska-Sabuka

Differential Equations 2014

Lecture 4 Nonhomogeneous and Nonlinear Systems


Numerical methods for ODEs

Methods for first-order ODEs


Methods for Systems and Higher-order ODEs

Classical Runge-Kutta Method


ALGORITHM RUNGE-KUTTA (f , x0 , y0 , h, n)
For n = 0, 1, . . . , n 1 do
k1 = hf (xn , yn )
k2 = hf (xn + 21 h, yn + 12 k1 )
k3 = hf (xn + 21 h, yn + 12 k2 )
k2 = hf (xn + h, yn + k3 )
xn+1 = xn + h
yn+1 = yn + 61 (k1 + 2k2 + 2k3 + k4 )
OUTPUT: xn+1 , yn+1
End
Stop
Matylda Jaboska-Sabuka

Differential Equations 2014

Lecture 4 Nonhomogeneous and Nonlinear Systems


Numerical methods for ODEs

Methods for first-order ODEs


Methods for Systems and Higher-order ODEs

Stiff problems
A stiff equation is a differential equation for which certain numerical
methods for solving the equation are numerically unstable, unless the step
size is taken to be extremely small. It has proved difficult to formulate a
precise definition of stiffness, but the main idea is that the equation
includes some terms that can lead to rapid variation in the solution.
Solving stiff equations can be a very long and hard process.
Backward (Implicit) Euler Method
The backward Euler formula for stiff problems
yn+1 = yn + hf (xn+1 , yn+1 )

Matylda Jaboska-Sabuka

Differential Equations 2014

Lecture 4 Nonhomogeneous and Nonlinear Systems


Numerical methods for ODEs

Methods for first-order ODEs


Methods for Systems and Higher-order ODEs

Multistep Methods
y 0 = f (x, y ), y (x0 ) = y0
Adams-Bashforth Methods
yn+1 = yn +

h
(55fn 59fn1 + 37fn2 9fn3 )
24

Adams-Bashforth Predictor, Adams-Moulton Corrector


h
(55fn 59fn1 + 37fn2 9fn3 )
24

= f (xn+1 , yn+1
)
h

= yn + (9fn+1
+ 19fn 5fn1 + fn2 )
24

yn+1
= yn +

fn+1

yn+1

Matylda Jaboska-Sabuka

Differential Equations 2014

Lecture 4 Nonhomogeneous and Nonlinear Systems


Numerical methods for ODEs

Methods for first-order ODEs


Methods for Systems and Higher-order ODEs

Euler Method for Systems


yn+1 = yn + hf(xn , yn )
Runge-Kutta Method for Systems
1
yn+1 = yn + (k1 + 2k2 + 2k3 + k4 )
6
Backward (Implicit) Euler Method for stiff problems
yn+1 = yn + hf(xn+1 , yn+1 )

Matylda Jaboska-Sabuka

Differential Equations 2014

Lecture 4 Nonhomogeneous and Nonlinear Systems


Numerical methods for ODEs

Methods for first-order ODEs


Methods for Systems and Higher-order ODEs

Matlab ODE solvers for nonstiff problems


ode45 is based on an explicit Runge-Kutta formula, the
Dormand-Prince pair. It is a one-step solver in computing
y (xn ), it needs only the solution at the immediately
preceding time point, y (xn1 ). In general, ode45 is the best
function to apply as a first try for most problems.
ode23 is an implementation of an explicit Runge-Kutta, pair of
Bogacki and Shampine. It may be more efficient than
ode45 at crude tolerances and in the presence of moderate
stiffness.
ode113 is a variable order Adams-Bashforth-Moulton PECE solver.
It may be more efficient than ode45 at stringent tolerances
and when the ODE file function is particularly expensive to
evaluate.
Matylda Jaboska-Sabuka

Differential Equations 2014

Lecture 4 Nonhomogeneous and Nonlinear Systems


Numerical methods for ODEs

Methods for first-order ODEs


Methods for Systems and Higher-order ODEs

ODE45 results
Difference between constant and variable step size when solving
y 0 = x + y , y (0) = 0.
h = 0.1
hn variable

CPU time
0.0312
0.1872

MSE
9.8416e-018
2.6404e-018

After changing the initial condition to y (0) = 5 we get


h = 0.1
hn variable

CPU time
0.0312
0.1872

Matylda Jaboska-Sabuka

MSE
3.5430e-016
9.5056e-017

Differential Equations 2014

Lecture 4 Nonhomogeneous and Nonlinear Systems


Numerical methods for ODEs

Methods for first-order ODEs


Methods for Systems and Higher-order ODEs

Matlab ODE solvers for stiff problems


ode15s is a variable order solver based on the numerical
differentiation formulas (NDFs). Optionally, it uses the
backward differentiation formulas (BDFs, also known as
Gears method) that are usually less efficient. Like ode113,
ode15s is a multistep solver. Try ode15s when ode45 fails,
or is very inefficient, and you suspect that the problem is
stiff, or when solving a differential-algebraic problem.
ode23s is based on a modified Rosenbrock formula of order 2.
Because it is a one-step solver, it may be more efficient than
ode15s at crude tolerances. It can solve some kinds of stiff
problems for which ode15s is not effective.

Matylda Jaboska-Sabuka

Differential Equations 2014

Lecture 4 Nonhomogeneous and Nonlinear Systems


Numerical methods for ODEs

Methods for first-order ODEs


Methods for Systems and Higher-order ODEs

Matlab ODE solvers


Solver
ode45
ode23
ode113
ode15s
ode23s

Problem Type
Nonstiff
Nonstiff
Nonstiff
Stiff
Stiff

Matylda Jaboska-Sabuka

Order of Accuracy
Medium
Low
Low to high
Low to medium
Low

Differential Equations 2014

Lecture 4 Nonhomogeneous and Nonlinear Systems


Numerical methods for ODEs

Methods for first-order ODEs


Methods for Systems and Higher-order ODEs

Consequences of solver choice nonstiff problems


y10 = y2 y3 ,

y1 (0) = 0

y20
y30

y2 (0) = 1

= y1 y3 ;

= 0.51y1 y2 ; y3 (0) = 1

t = [0, 12]
With ode45 the solution takes about 0.38sec.
With ode15s the solution takes about 0.59sec.
The stiff solver can treat a nonstiff problem efficiently with minor solution
difference.

Matylda Jaboska-Sabuka

Differential Equations 2014

Lecture 4 Nonhomogeneous and Nonlinear Systems


Numerical methods for ODEs

Methods for first-order ODEs


Methods for Systems and Higher-order ODEs

Consequences of solver choice stiff problems


An example of a stiff system is provided by the van der Pol equations in
relaxation oscillation. The limit cycle has portions where the solution
components change slowly and the problem is quite stiff, alternating with
regions of very sharp change where it is not stiff.
y10 = y2 ,
y20

= 1000(1

y1 (0) = 0
y12 )y2

y1 ; y2 (0) = 1

t = [0, 3000]
With ode15s the solution takes about 1sec.
The nonstiff solver (ode45) cannot handle the problem in reasonable
time, and significantly influences the solution.

Matylda Jaboska-Sabuka

Differential Equations 2014

Potrebbero piacerti anche