Transcript
Page 1: 559 Fish 559; Lecture 2 Numerical Integration Methods

559

Fish 559; Lecture 2

Numerical Integration Methods

Page 2: 559 Fish 559; Lecture 2 Numerical Integration Methods

559

Some Preliminaries-I Numerical methods are numerical and

hence subject to various types of errors: Roundoff error: The consequences of a

computer representing a real number using finite accuracy. Note:

roundoff errors accumulate; and subtraction of two numbers that are nearly

identical may lead to very large roundoff errors. Truncation error: the difference between the

true answer and the value from the numerical analysis.

Page 3: 559 Fish 559; Lecture 2 Numerical Integration Methods

559

Some Preliminaries-II Truncation error:

There are often error bounds for methods (though we will not consider these in this course).

Truncation error can be reduced by increasing the number of steps / reducing tolerances or step sizes, but this can be costly in terms of computation time and, eventually, roundoff error will begin to impact the results.

Page 4: 559 Fish 559; Lecture 2 Numerical Integration Methods

559

Numerical Integration(or numerical quadrature)

The objective of numerical integration is to solve the problem:

which is equivalent to finding subject to:

We will assume that the function f cannot be integrated analytically!

( )b

a

I f x dx( )y b

( ); ( ) 0dy

f x y adx

Page 5: 559 Fish 559; Lecture 2 Numerical Integration Methods

559

Numerical Integration(why do this)

The density of larvae is given by the function f (as a function of distance along a river); how many larvae are there between points a and b along the river?

Let f be the function that determines the rate of change in the number of animals of species i (which depends on the number of animals of species i). If there are 1,000 animals of species i at time t0, how many are there at time t0+1.

Page 6: 559 Fish 559; Lecture 2 Numerical Integration Methods

559

Numerical Integration(An example problem)

We wish to evaluate the integral:

21

0

xI e dx

X

Y

-1.0 -0.5 0.0 0.5 1.0 1.5 2.0

0.0

0.4

0.8

1.2

Page 7: 559 Fish 559; Lecture 2 Numerical Integration Methods

559

Numerical Integration(Single-step approaches-I)

We could approximate the integral by its height at its first point, at its last point, or at the middle.

Approximating the integral by the average of the first two approaches is the “Trapezoidal rule”.

X

Y

-1.0 -0.5 0.0 0.5 1.0 1.5 2.0

0.0

0.4

0.8

1.2

X

Y

-1.0 -0.5 0.0 0.5 1.0 1.5 2.0

0.0

0.4

0.8

1.2

Page 8: 559 Fish 559; Lecture 2 Numerical Integration Methods

559

Numerical Integration(Single-step approaches-II)

We wish to integrate from a to b. We have formulae that get more accurate as more terms are added:

Trapezoidal rule:

Simpson’s Rule:

Boole’s rule:

h is the step size. It is (b-a) divided by the number of function calls less 1.

There are many variants on this theme!

1 12 2( ) ( )I h f a f b

1 4 13 3 3( ) ( ) ( )I h f a f a h f b

64 6414 24 1445 45 45 45 45( ) ( ) ( 2 ) ( 3 ) ( )I h f a f a h f a h f a h f b

X

Y

-1.0 -0.5 0.0 0.5 1.0 1.5 2.0

0.0

0.4

0.8

1.2

http://en.wikipedia.org/wiki/George_Boole

Page 9: 559 Fish 559; Lecture 2 Numerical Integration Methods

559

Numerical Integration(Single-step approaches-III)

Results: Trapezodinal rule: 0.68394 Simpson’s rule: 0.74718 Boole’s rule: 0.74683 Exact: 0.74682!

Page 10: 559 Fish 559; Lecture 2 Numerical Integration Methods

559

Numerical Integration(Multi-step rules)

Therefore, in order to numerically integrate over the interval [a, c], we can apply one of the single-step rules multiple times and add the results, i.e. for Simpson’s rule:

Now : ( ) ( ) ( )c b c

a a b

f x dx f x dx f x dx

1 4 2 4 11 2 3 13 3 3 3 3... N NI h f f f f f

Page 11: 559 Fish 559; Lecture 2 Numerical Integration Methods

559

Other Approaches(Gaussian quadrature-I)

Generalizing the previous approaches:

The previous methods have all been based on equal spacing along abscissa. We can improve our accuracy (at the expense of a bit more programming) by allowing freedom in the location of the absciccas.

( )i ii

I w f x

1 1 1'

1 1 1

( ) ( ( )) ( ) ( ( )) ( ( ))2 2

( ( )) "( )2 2

b

a

i i i ii i

b a b aI f x dx f x t x t dt f x t dt f x t dt

b a b aI w f x t w f t

Page 12: 559 Fish 559; Lecture 2 Numerical Integration Methods

559

Other Approaches(Gaussian quadrature-II)

For two point Gaussian quadrature:

This lead to an approximation to the integral of 0.74965. The three point formula leads to 0.74673.

Abramowitz and Stegun provide details on the absiccas and weights for equations of different orders (numbers of terms in the approximating equation).

( 0.57735026) (0.57735026)2

b aI f f

2 2 21

( 1) / 4 (1 ) / 412

0

[ ]; 0.5773502691x x xe dx e e x

Page 13: 559 Fish 559; Lecture 2 Numerical Integration Methods

559

The Error Function Perhaps the most frequently required

integral in fisheries is the “error function”:

It is not necessary to apply the methods of this lecture to compute this integral because very accurate approximations to it have been programmed and are available in software libraries (e.g. NORMDIST in EXCEL, cumd_norm in ADMB and pnorm in R).

The lesson from this example, is that someone may have already solved your problem; before writing your own code check whether this is the case!

2 / 2a

xI e dx

Page 14: 559 Fish 559; Lecture 2 Numerical Integration Methods

559

Multidimensional Integrals Multidimensional integrals are much

more complicated than single-dimensional integrals. There are a few basic approaches to computing these integrals: Split the problem into multiple single

dimensional integrals. Use Monte Carlo methods. Use numerical methods (such as Laplace’s

method). The issue of computing

multidimensional integrals using Monte Carlo methods will be discussed later.

Page 15: 559 Fish 559; Lecture 2 Numerical Integration Methods

559

Integration of ODEs The generic problem is the study of a

set of N coupled first order differential equations:

The specification of ODEs generally includes initial conditions, i.e.:

1

( )( , ,.., ); 1, 2,....,ii N

dy xf x y y i N

dx

(0) ; 1,2,...,i iy Y i N

Page 16: 559 Fish 559; Lecture 2 Numerical Integration Methods

559

A Familiar Set of ODEs (Ecosim)

The initial conditions are determined from Ecopath.

, , ( )ii j i i j i i i i ij j

dBg C C I M F e B

dt

Consumption of species i by species j

Net growth efficiency Immigration

Non-predation mortality, fishing mortality and

emigration

Page 17: 559 Fish 559; Lecture 2 Numerical Integration Methods

559

Euler’s Method Euler’s method updates the solution

from xn to xn+1=xn+h using the formula:

This method is simple, but can be very inaccurate (unless a very small step-size is used).

1 ( , )n n n ny y hf x y

Page 18: 559 Fish 559; Lecture 2 Numerical Integration Methods

559

Other Ways to Solve ODEs Runge-Kutta methods. Richardson extrapolation. Predictor-corrector methods.

We will focus on the Runge-Kutta method.

Page 19: 559 Fish 559; Lecture 2 Numerical Integration Methods

559

Runge-Kutta Methods-I These tend to perform adequately

for many problems (but more efficient algorithms do exist).

The step size (h) can be monitored and modified automatically to improve performance.

Page 20: 559 Fish 559; Lecture 2 Numerical Integration Methods

559

Runge-Kutta Methods-II There are many versions of the Runge-

Kutta method but the fourth-order version seems the most popular:

There are multidimensional versions of the RK algorithm.

31 2 4

1 6 3 3 6kk k k

n ny y 1

2

1

2 2 2

3 2 2

4 3

( , )

( , )

( , )

( , )

n n

khn n

khn n

n n

k hf x y

k hf x y

k hf x y

k hf x h y k

Page 21: 559 Fish 559; Lecture 2 Numerical Integration Methods

559

An Example-I Solve the following ODE using (a)

Euler’s method and (b) the Runge-Kutta fourth-order method:

where:

(1 ) ; (1 / )du au v dv

u u bv v udt u d dt

(0) 1.2; (0) 0.2; 1; 0.2; 0.1u v a b d

Page 22: 559 Fish 559; Lecture 2 Numerical Integration Methods

559

An Example -II

uu

vv

0.2 0.4 0.6 0.8 1.0 1.2

0.15

0.25

0.35

Runge-Kutta

Euler

Page 23: 559 Fish 559; Lecture 2 Numerical Integration Methods

559

Moving to PDEs Partial Differential Equations

(PDEs) are much more difficult to solve.

Although algorithms do exist to solve these, the literature is vast and we will not discuss them in this course.

Page 24: 559 Fish 559; Lecture 2 Numerical Integration Methods

559

Numerical Instability-I We wish to solve the following

initial value problem:

We can apply Euler’s method:

or Milne’s method:

2 1dy

ydx

(0) 1y

1n n ny y h f

1 1 2n n ny y hf

Page 25: 559 Fish 559; Lecture 2 Numerical Integration Methods

559

Numerical Instability-II

X

Error

0 1 2 3 4

-10

-50

510

Euler’s method is stable but Milne’s ruleBecomes unstable after x=2!

In the case, we knew the correct solution, what would we do in reality?


Recommended