Vous êtes sur la page 1sur 10

Numerical Integration and Differentiation

Computational Economics

Dietmar Maringer
WWZ, University of Basel

Spring 2012

D Maringer, Computational Economics

Numerical Integration and Differentiation

(1)

Finite Differences for Numerical Differentiation


basic concepts
difference quotient:
derivative:

y
x

f (x0 +x)f (x0 )


x
dy
y
0

f
(x)

lim
x 0 x
dx

f (x + )

numerical approximation of f 0 with central


difference
f (x + ) f (x )
(x + ) (x )
f (x + ) f (x )
where 0
=
2

f (x )

f 0 (x)

x+

x +

x
x

multi-dimensional functions
gradient: list of all first order derivatives
f =

f
x1

f
xn

h
f (x1 +,x2 ,...,xn )2f (x1 ,x2 ,...,xn )

D Maringer, Computational Economics

f (x1 ,x2 ,...,xn +)f (x1 ,x2 ,...,xn )


2

Numerical Integration and Differentiation

(2)

Finite Differences for Numerical Differentiation


second derivative for one-dimensional functions
since second derivative = derivative of first derivative, compute by
iteratively applying definitions:
f 00 (x)
=

f 0 (x + ) f 0 (x )
(x + ) (x )
f (x++)f (x+)
2

f (x+)f (x)
2

(x + ) (x )
f (x + 2) + f (x 2) 2f (x)
=
(2)2
f (x + ) + f (x ) 2f (x)

where = 2
likewise for higher derivatives

D Maringer, Computational Economics

Numerical Integration and Differentiation

(3)

Finite Differences for Numerical Differentiation


second derivative for multi-dimensional functions
Hessian matrix multi-dimensional functions: matrix of all second
order derivatives

H=

2 f
x21

..
.

2 f
xn x1

2 f
xi xj

2 f
x1 xn

..
.

2 f
x2n

usually, Hessian is symmetric, i.e.,

D Maringer, Computational Economics

2 f
xi xj

2 f

= x x
j i

Numerical Integration and Differentiation

(4)

Finite Differences for Numerical Differentiation


numerical approximation of the Hessian
vary values in dimensions i and j (leaving all other values unchanged)
and evaluate points
xj

xi
f
f
x
i

f +

xi +

xj
f
f
f +

xj +
f +
f +
f ++

diagonal elements of the Hessian matrix


2 f
x2i

( f + +f 2f
+2

1 f
2

alternative 1

2f

+f

f ++ +f + 2f +
2

alternative 2

off-diagonal elements of the Hessian matrix (cross-derivatives)


+ +

f +f f f
f + +f f + f

+
12
2
2

++ + +

2 f
f +f f f
f +f f f
12
+
2
2

xi xj

1 f ++ +f f + f +

D Maringer, Computational Economics

alternative 1
alternative 2
average alt.s 1 and 2

Numerical Integration and Differentiation

(5)

Application Example
local approximation with Taylor Series Approximation
approximation for region around a given value x0
approximate function value at x = x0 + with a polynomial
f (x) = f (x0 + ) = f (x0 ) + f 0 (x0 ) +

f 00 (x0 ) +

+ +

f 000 (x0 ) +

n (n)
f (x0 ) + Rn

n!

remainder Rn < |x x0 |n+1

D Maringer, Computational Economics

Numerical Integration and Differentiation

(6)

Numerical Integration with Trapezoid Rule


basic idea
assume function is approximately piecewise linear
area underneath each line segment is a trapezoid
integral is the sum of all trapezoids areas

f3
f2 +f3
2
f2
w
a

= x1

x2

D Maringer, Computational Economics

f2 +f3
2

x3

=bx4

Numerical Integration and Differentiation

(7)

Numerical Integration with Trapezoid Rule


Rb

how solve a problem like f (x)dx


a

split range into n segments of equal width w = (b a)/n


compute borders of segments, xi = a + (i 1)w for i = 1..(n + 1)
approximation for area of one segment:
for the entire range (with fi = f (xi ))
Z b
a

f (x)dx =

n Z xi+1
X
i=1 xi
n
X

i=1

R xi+1
xi

f (x)dx w

f (xi )+f (xi+1 )


2

f (x)dx

f1
fn+1
fi + fi+1
= w
+ f2 + + fn +
2
2
2

more generally (when segments have different width):


Z b
a

f (x)dx

n
X

(xi+1 xi )

i=1

fi + fi+1
2

extension: Simpsons rule (piecewise quadratic functions)


D Maringer, Computational Economics

Numerical Integration and Differentiation

(8)

Numerical Integration with Monte Carlo Simulation


some (very) simple examples
1
f (x) = x =
2

Z 2
0

f (x)dx =?

f (x) = sin |x|

p
5
|x|

Z 3
=

f (x)dx =?

Estimating the Value of via MCS


A = (2r)2

A = r 2
A r2
=
=
A 4r2 4
A
= = 4
A

r
1

y
1

1
D Maringer, Computational Economics

Numerical Integration and Differentiation

(9)

additional literature
Gilli, M., Maringer, D., and Schumann, E. (2011).
Numerical Methods and Optimization in Finance.
Academic Press.
Judd, K. L. (1998).
Numerical Methods in Economics.
MIT Press.
Miranda, M. J. and Fackler, P. L. (2002).
Applied Computational Economics and Finance.
MIT Press.

D Maringer, Computational Economics

Numerical Integration and Differentiation

(10)

Vous aimerez peut-être aussi