ce_12_01_numdiffint
Post on 02-Jun-2018
224 Views
Preview:
TRANSCRIPT
-
8/10/2019 CE_12_01_NumDiffInt
1/10
Numerical Integration and DifferentiationComputational Economics
Dietmar Maringer
WWZ, University of Basel
Spring 2012
D Maringer,Computational Economics Numerical Integration and Differentiation (1)
-
8/10/2019 CE_12_01_NumDiffInt
2/10
Finite Differences for Numerical Differentiation
basic concepts
difference quotient: yx=
f(x0+x)f(x0)x
derivative: dydxf(x) limx0 yx
numerical approximation offwith centraldifference
f(x)
f(x+)f(x)(x+) (x)
= f(x+)f(x)2
where 0
xx
x+
x
f(x)x+
f(x+)
multi-dimensional functions
gradient: list of all first order derivatives
f= fx1
fxn
f(x1+,x2,...,xn)f(x1,x2,...,xn)2
f(x1,x2,...,xn+)f(x1,x2,...,xn)2
D Maringer,Computational Economics Numerical Integration and Differentiation (2)
-
8/10/2019 CE_12_01_NumDiffInt
3/10
Finite Differences for Numerical Differentiation
second derivative for one-dimensional functions
since second derivative = derivative of first derivative, compute by
iteratively applying definitions:
f(x) f(x+)f(x )(x+) (x)
=
f(x++)f(x+)2
f(x+)f(x)2
(x+) (x)= f(x+2)+f(x2)2f(x)
(2)2
= f(x+)+f(x)2f(x)2
where = 2likewise for higher derivatives
D Maringer,Computational Economics Numerical Integration and Differentiation (3)
-
8/10/2019 CE_12_01_NumDiffInt
4/10
Finite Differences for Numerical Differentiation
second derivative for multi-dimensional functions
Hessian matrix multi-dimensional functions: matrix of all second
order derivatives
H=
2f
x21
2fx1xn
...
2f
xixj
...
2f
xnx1
2f
x2n
usually, Hessian is symmetric, i.e.,
2fxixj
= 2f
xjxi
D Maringer,Computational Economics Numerical Integration and Differentiation (4)
-
8/10/2019 CE_12_01_NumDiffInt
5/10
Finite Differences for Numerical Differentiation
numerical approximation of the Hessian
vary values in dimensionsiandj(leaving all other values unchanged)
and evaluate points
xj xj xj+xi f f f+xi f
f f+xi+ f+ f+ f++
diagonal elements of the Hessian matrix
2f
x2i
f++f2f
2 alternative 1
12
f++f2f
2 + f
+++f+2f+2
alternative 2
off-diagonal elements of the Hessian matrix (cross-derivatives)
2f
xixj
12
f++fff+
2 + f
++ff+f2
alternative 1
12
f+f++f+f+
2 + f
+fff2
alternative 2
14
f+++ff+f+2 average alt.s 1 and 2
D Maringer,Computational Economics Numerical Integration and Differentiation (5)
-
8/10/2019 CE_12_01_NumDiffInt
6/10
Application Example
local approximation with Taylor Series Approximation
approximation for region around a given valuex0
approximate function value atx= x0+with a polynomial
f(x)=f(x0+)=f(x0)+f(x0)+
2
2 f(x0)+
3
6 f(x0)+
+ +
n
n!f(n)
(x0)+Rn
remainderRn < |xx0|n+1
D Maringer,Computational Economics Numerical Integration and Differentiation (6)
i l i i h id l
-
8/10/2019 CE_12_01_NumDiffInt
7/10
Numerical Integration with Trapezoid Rule
basic idea
assume function is approximately piecewise linear
area underneath each line segment is a trapezoidintegral is the sum of all trapezoids areas
=x1
=x4x2 x3
f2
f3f2+f3
2
wa b
w f2+f32
D Maringer,Computational Economics Numerical Integration and Differentiation (7)
N i l I i i h T id R l
-
8/10/2019 CE_12_01_NumDiffInt
8/10
Numerical Integration with Trapezoid Rule
how solve a problem likeb
af(x)dx
split range intonsegments of equal widthw= (ba)/ncompute borders of segments,xi = a+ (i1)wfori= 1..(n+1)approximation for area of one segment:
xi+1xi
f(x)dxwf(xi)+f(xi+1)2for the entire range (withfi =f(xi))
b
af(x)dx= n
i=1
xi+1
xi
f(x)dx
n
i=1w fi+fi+1
2 =w
f12+f2+ +fn+
fn+12
more generally (when segments have different width):ba
f(x)dxn
i=1(xi+1xi)
fi+fi+12
extension: Simpsons rule (piecewise quadratic functions) D Maringer,Computational Economics Numerical Integration and Differentiation (8)
N i l I t ti ith M t C l Si l ti
-
8/10/2019 CE_12_01_NumDiffInt
9/10
Numerical Integration with Monte Carlo Simulation
some (very) simple examples
f(x)= 12
x=
2
0f(x)dx=? f(x)= sin
|x| 5
|x|=
3
1f(x)dx=?
Estimating the Value ofvia MCS
A = (2r)2
A = r2AA
= r2
4r2=
4
== 4AA
y
x
r
1 1
1
1
D Maringer,Computational Economics Numerical Integration and Differentiation (9)
dditi l lit t
-
8/10/2019 CE_12_01_NumDiffInt
10/10
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)