38
Numerical Methods-Lecture V-Newton’s Method Trevor Gallen Fall, 2015 1/1

Numerical Methods-Lecture V-Newton's ... - Purdue Universityweb.ics.purdue.edu/~tgallen/Teaching/Econ_690_Fall...derivative: x n+1 = x n f0(x n) f00(x n) and: X n+1 = X n H 1f0(x n)

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Numerical Methods-Lecture V-Newton's ... - Purdue Universityweb.ics.purdue.edu/~tgallen/Teaching/Econ_690_Fall...derivative: x n+1 = x n f0(x n) f00(x n) and: X n+1 = X n H 1f0(x n)

Numerical Methods-LectureV-Newton’s Method

Trevor Gallen

Fall, 2015

1 / 1

Page 2: Numerical Methods-Lecture V-Newton's ... - Purdue Universityweb.ics.purdue.edu/~tgallen/Teaching/Econ_690_Fall...derivative: x n+1 = x n f0(x n) f00(x n) and: X n+1 = X n H 1f0(x n)

GoalsAim is to teach numerical methods, give you the tools you need towrite down, solve, and estimate models

1. Interpolation

2. Numerical derivatives

3. Maximization/minimization

I Deterministic, stochastic

I Derivative-based, derivative-free

I Local, global

4. Numerical integration/quadrature

5. Bellman equations2 / 1

Page 3: Numerical Methods-Lecture V-Newton's ... - Purdue Universityweb.ics.purdue.edu/~tgallen/Teaching/Econ_690_Fall...derivative: x n+1 = x n f0(x n) f00(x n) and: X n+1 = X n H 1f0(x n)

Motivation

I We have some function f (x)

I Want to find x∗ such that f (x∗) = 0.

I Examples:

I Equilibrium conditions: X S(p) − XD(p) = 0

I Maximization conditions: u′(c) − λ = 0

3 / 1

Page 4: Numerical Methods-Lecture V-Newton's ... - Purdue Universityweb.ics.purdue.edu/~tgallen/Teaching/Econ_690_Fall...derivative: x n+1 = x n f0(x n) f00(x n) and: X n+1 = X n H 1f0(x n)

Newton’s Method: Idea

1. Take a linear approximation of function, find slope andintercept

2. Given equation of line, solve for zero

3. Take that new point, repeat.

4 / 1

Page 5: Numerical Methods-Lecture V-Newton's ... - Purdue Universityweb.ics.purdue.edu/~tgallen/Teaching/Econ_690_Fall...derivative: x n+1 = x n f0(x n) f00(x n) and: X n+1 = X n H 1f0(x n)

Newton’s Method Derivation

1. Take Taylor expansion: f (x) ≈ f (x0) + ∂f (x)∂x

∣∣∣x=x0

(x − x0)

2. Set equal to zero: 0 = f (x0) + ∂f (x)∂x

∣∣∣x=x0

(x − x0)

3. Solve for x: x = x0 − f (x0)∂f (x)∂x

∣∣∣x=x0

4. Call x x0 repeat.

In other words, the interative procedure:

xn+1 = xn −f (xn)

f ′(xn)

5 / 1

Page 6: Numerical Methods-Lecture V-Newton's ... - Purdue Universityweb.ics.purdue.edu/~tgallen/Teaching/Econ_690_Fall...derivative: x n+1 = x n f0(x n) f00(x n) and: X n+1 = X n H 1f0(x n)

Example: f (x) = sin(x), x0 = 1

1. x1 = sin(1) − sin(1)cos(1) = 1 − 0.8414

0.5403 = −0.56

2. x2 = −0.56 − sin(−0.56)cos(−0.56) = −0.56 − 0.53

0.85 = 0.07

3. x3 = 0.07 − sin(0.07)cos(0.07) = 0.07 − 0.07

1 = −1e − 4

4. And so on until xi ≈ 0.

Note: I round.

6 / 1

Page 7: Numerical Methods-Lecture V-Newton's ... - Purdue Universityweb.ics.purdue.edu/~tgallen/Teaching/Econ_690_Fall...derivative: x n+1 = x n f0(x n) f00(x n) and: X n+1 = X n H 1f0(x n)

Do different starting places matter?

Iteration Trial 1 Trial 2 Trial 3 Trial 4 Trial 5

0 1 0.5 2 3.5 1.41 -.56 -0.05 4.1 3.13 -4.402 0.07 3e-5 2.4 3.14 1.323 -1e-4 -1e-14 3.2 3.14 2.64...

......

......

...10 0 0 3.14... 3.14... 3.14...

A little, and a lot.

7 / 1

Page 8: Numerical Methods-Lecture V-Newton's ... - Purdue Universityweb.ics.purdue.edu/~tgallen/Teaching/Econ_690_Fall...derivative: x n+1 = x n f0(x n) f00(x n) and: X n+1 = X n H 1f0(x n)

Newton’s Method, Graphically-I

8 / 1

Page 9: Numerical Methods-Lecture V-Newton's ... - Purdue Universityweb.ics.purdue.edu/~tgallen/Teaching/Econ_690_Fall...derivative: x n+1 = x n f0(x n) f00(x n) and: X n+1 = X n H 1f0(x n)

Newton’s Method, Graphically-II

9 / 1

Page 10: Numerical Methods-Lecture V-Newton's ... - Purdue Universityweb.ics.purdue.edu/~tgallen/Teaching/Econ_690_Fall...derivative: x n+1 = x n f0(x n) f00(x n) and: X n+1 = X n H 1f0(x n)

Newton’s Method, Graphically-III

10 / 1

Page 11: Numerical Methods-Lecture V-Newton's ... - Purdue Universityweb.ics.purdue.edu/~tgallen/Teaching/Econ_690_Fall...derivative: x n+1 = x n f0(x n) f00(x n) and: X n+1 = X n H 1f0(x n)

Newton’s Method, Graphically-IV

11 / 1

Page 12: Numerical Methods-Lecture V-Newton's ... - Purdue Universityweb.ics.purdue.edu/~tgallen/Teaching/Econ_690_Fall...derivative: x n+1 = x n f0(x n) f00(x n) and: X n+1 = X n H 1f0(x n)

Newton’s Method, Graphically-V

12 / 1

Page 13: Numerical Methods-Lecture V-Newton's ... - Purdue Universityweb.ics.purdue.edu/~tgallen/Teaching/Econ_690_Fall...derivative: x n+1 = x n f0(x n) f00(x n) and: X n+1 = X n H 1f0(x n)

Newton’s Method, Graphically-VI

13 / 1

Page 14: Numerical Methods-Lecture V-Newton's ... - Purdue Universityweb.ics.purdue.edu/~tgallen/Teaching/Econ_690_Fall...derivative: x n+1 = x n f0(x n) f00(x n) and: X n+1 = X n H 1f0(x n)

Newton’s Method, Graphically-VII

14 / 1

Page 15: Numerical Methods-Lecture V-Newton's ... - Purdue Universityweb.ics.purdue.edu/~tgallen/Teaching/Econ_690_Fall...derivative: x n+1 = x n f0(x n) f00(x n) and: X n+1 = X n H 1f0(x n)

Newton’s Method, Graphically-VIII

15 / 1

Page 16: Numerical Methods-Lecture V-Newton's ... - Purdue Universityweb.ics.purdue.edu/~tgallen/Teaching/Econ_690_Fall...derivative: x n+1 = x n f0(x n) f00(x n) and: X n+1 = X n H 1f0(x n)

Newton’s Method, Graphically-IX

16 / 1

Page 17: Numerical Methods-Lecture V-Newton's ... - Purdue Universityweb.ics.purdue.edu/~tgallen/Teaching/Econ_690_Fall...derivative: x n+1 = x n f0(x n) f00(x n) and: X n+1 = X n H 1f0(x n)

Newton’s Method, Graphically, New StartingPoint

17 / 1

Page 18: Numerical Methods-Lecture V-Newton's ... - Purdue Universityweb.ics.purdue.edu/~tgallen/Teaching/Econ_690_Fall...derivative: x n+1 = x n f0(x n) f00(x n) and: X n+1 = X n H 1f0(x n)

Newton’s Method, Graphically-XI

18 / 1

Page 19: Numerical Methods-Lecture V-Newton's ... - Purdue Universityweb.ics.purdue.edu/~tgallen/Teaching/Econ_690_Fall...derivative: x n+1 = x n f0(x n) f00(x n) and: X n+1 = X n H 1f0(x n)

Newton’s Method, Graphically-XII

19 / 1

Page 20: Numerical Methods-Lecture V-Newton's ... - Purdue Universityweb.ics.purdue.edu/~tgallen/Teaching/Econ_690_Fall...derivative: x n+1 = x n f0(x n) f00(x n) and: X n+1 = X n H 1f0(x n)

Newton’s Method, Graphically-XIII

20 / 1

Page 21: Numerical Methods-Lecture V-Newton's ... - Purdue Universityweb.ics.purdue.edu/~tgallen/Teaching/Econ_690_Fall...derivative: x n+1 = x n f0(x n) f00(x n) and: X n+1 = X n H 1f0(x n)

Newton’s Method, Graphically-XIV

21 / 1

Page 22: Numerical Methods-Lecture V-Newton's ... - Purdue Universityweb.ics.purdue.edu/~tgallen/Teaching/Econ_690_Fall...derivative: x n+1 = x n f0(x n) f00(x n) and: X n+1 = X n H 1f0(x n)

Newton’s Method, Graphically-XV

22 / 1

Page 23: Numerical Methods-Lecture V-Newton's ... - Purdue Universityweb.ics.purdue.edu/~tgallen/Teaching/Econ_690_Fall...derivative: x n+1 = x n f0(x n) f00(x n) and: X n+1 = X n H 1f0(x n)

Newton’s Method, Graphically-XVI

23 / 1

Page 24: Numerical Methods-Lecture V-Newton's ... - Purdue Universityweb.ics.purdue.edu/~tgallen/Teaching/Econ_690_Fall...derivative: x n+1 = x n f0(x n) f00(x n) and: X n+1 = X n H 1f0(x n)

Newton’s Method, Graphically-XVII

24 / 1

Page 25: Numerical Methods-Lecture V-Newton's ... - Purdue Universityweb.ics.purdue.edu/~tgallen/Teaching/Econ_690_Fall...derivative: x n+1 = x n f0(x n) f00(x n) and: X n+1 = X n H 1f0(x n)

Newton’s Method, Graphically-XVIII

25 / 1

Page 26: Numerical Methods-Lecture V-Newton's ... - Purdue Universityweb.ics.purdue.edu/~tgallen/Teaching/Econ_690_Fall...derivative: x n+1 = x n f0(x n) f00(x n) and: X n+1 = X n H 1f0(x n)

Benefits, Costs

I Newton’s method is quite rapid (locally quadraticallyconvergent)

I Requires smoothness/derivative

I Can get trapped at local minima

I Can be sensitive to starting points

26 / 1

Page 27: Numerical Methods-Lecture V-Newton's ... - Purdue Universityweb.ics.purdue.edu/~tgallen/Teaching/Econ_690_Fall...derivative: x n+1 = x n f0(x n) f00(x n) and: X n+1 = X n H 1f0(x n)

One dimension is easy...how about two?

Before, scalar equation:f (x) = 0

Now: [f [1](x1, x2)

f [2](x1, x2)

]=

[00

]

27 / 1

Page 28: Numerical Methods-Lecture V-Newton's ... - Purdue Universityweb.ics.purdue.edu/~tgallen/Teaching/Econ_690_Fall...derivative: x n+1 = x n f0(x n) f00(x n) and: X n+1 = X n H 1f0(x n)

Newton’s Method: Vector of Equations

[f [1](x1, x2)

f [2](x1, x2)

]=

[00

]The Jacobian (matrix of first derivatives):

Df =

[∂f [1]

∂x1∂f [1]

∂x2∂f [2]

∂x1∂f [2]

∂x2

]

So we can take the multivariate taylor expansion, in matrix form:[f [1](x1, x2)

f [2](x1, x2)

]≈[f [1](x1, x2)

f [2](x1, x2)

]+

[∂f [1]

∂x1∂f [1]

∂x2∂f [2]

∂x1∂f [2]

∂x2

]([x1x2

]−[x1x2

])

28 / 1

Page 29: Numerical Methods-Lecture V-Newton's ... - Purdue Universityweb.ics.purdue.edu/~tgallen/Teaching/Econ_690_Fall...derivative: x n+1 = x n f0(x n) f00(x n) and: X n+1 = X n H 1f0(x n)

Newton’s Method: Vector of Equations

Set it equal to zero:[00

]=

[f [1](x1, x2)

f [2](x1, x2)

]+

[∂f [1]

∂x1∂f [1]

∂x2∂f [2]

∂x1∂f [2]

∂x2

]([x1x2

]−[x1x2

])

Solving for

[x1x2

]assuming and inverse matrix:

[x1x2

]=

[x1x2

]−

[∂f [1]

∂x1∂f [1]

∂x2∂f [2]

∂x1∂f [2]

∂x2

]−1 [f [1](x1, x2)

f [2](x1, x2)

]Or, with obvious notation for the vector X , X̄ , F , and the jacobianof F , J:

Xn+1 = X̄n − J−1F (X̄n)

29 / 1

Page 30: Numerical Methods-Lecture V-Newton's ... - Purdue Universityweb.ics.purdue.edu/~tgallen/Teaching/Econ_690_Fall...derivative: x n+1 = x n f0(x n) f00(x n) and: X n+1 = X n H 1f0(x n)

Example-I

[f [1](x1, x2)

f [2](x1, x2)

]=

[exp(x1) − 2 exp(x2)

x1 + x2 − 3

]So we can write:

J(X ) =

[exp(x1) −2 exp(x2)

1 1

]

J(X )−1 =1

exp(x1) + 2 exp(x2)

[1 2 exp(x2)−1 exp(x1)

]

30 / 1

Page 31: Numerical Methods-Lecture V-Newton's ... - Purdue Universityweb.ics.purdue.edu/~tgallen/Teaching/Econ_690_Fall...derivative: x n+1 = x n f0(x n) f00(x n) and: X n+1 = X n H 1f0(x n)

Example-II

Start at (0, 0):[x1x2

]=

[00

]−[

0.33 0.66−0.33 0.66

]−1 [ −1−3

]=

[2.330.66

][x1x2

]=

[2.330.66

]−[

0.07 0.27−0.07 0.72

]−1 [6.41

0

]=

[2.881.11

]And so on until the solution, x1 = 1.84 and x2 = 1.15

31 / 1

Page 32: Numerical Methods-Lecture V-Newton's ... - Purdue Universityweb.ics.purdue.edu/~tgallen/Teaching/Econ_690_Fall...derivative: x n+1 = x n f0(x n) f00(x n) and: X n+1 = X n H 1f0(x n)

Example-II: First equation and zeros

32 / 1

Page 33: Numerical Methods-Lecture V-Newton's ... - Purdue Universityweb.ics.purdue.edu/~tgallen/Teaching/Econ_690_Fall...derivative: x n+1 = x n f0(x n) f00(x n) and: X n+1 = X n H 1f0(x n)

Example-II: Second equation and zeros

33 / 1

Page 34: Numerical Methods-Lecture V-Newton's ... - Purdue Universityweb.ics.purdue.edu/~tgallen/Teaching/Econ_690_Fall...derivative: x n+1 = x n f0(x n) f00(x n) and: X n+1 = X n H 1f0(x n)

Example-II: Both Equations and zeros

34 / 1

Page 35: Numerical Methods-Lecture V-Newton's ... - Purdue Universityweb.ics.purdue.edu/~tgallen/Teaching/Econ_690_Fall...derivative: x n+1 = x n f0(x n) f00(x n) and: X n+1 = X n H 1f0(x n)

Example-II: Both Equations and zeros(rotated)

35 / 1

Page 36: Numerical Methods-Lecture V-Newton's ... - Purdue Universityweb.ics.purdue.edu/~tgallen/Teaching/Econ_690_Fall...derivative: x n+1 = x n f0(x n) f00(x n) and: X n+1 = X n H 1f0(x n)

Equations, approximations, and zeros

Start at (0,0), take tangent planes, find where planes intersectwith zero (green lines), find where lines intersect (new point). Inthis case, red and green line are same because linear expansion oflinear plane is plane.

36 / 1

Page 37: Numerical Methods-Lecture V-Newton's ... - Purdue Universityweb.ics.purdue.edu/~tgallen/Teaching/Econ_690_Fall...derivative: x n+1 = x n f0(x n) f00(x n) and: X n+1 = X n H 1f0(x n)

Minimization

Conceptually, minimization is the same: just find the zeros of thederivative:

xn+1 = xn −f ′(xn)

f ′′(xn)

and:Xn+1 = Xn − H−1f ′(xn)

37 / 1

Page 38: Numerical Methods-Lecture V-Newton's ... - Purdue Universityweb.ics.purdue.edu/~tgallen/Teaching/Econ_690_Fall...derivative: x n+1 = x n f0(x n) f00(x n) and: X n+1 = X n H 1f0(x n)

Extensions

I 80% of the minimization and solving methods you meet willbe derivative-based twists of Newton’s Method

I Halley’s Method, Householder Methods: Higher-orderderivatives

I Quasi-Newton Methods: If you can’t take J, approximate it

I Secant Method: Newton’s Method with finite differences

I Gauss-Newton: Minimize sum of squared functions

I Lecture 2 talks about alternatives

38 / 1