Numerical Methods-Lecture VI: Applying Newton's Method

40
Numerical Methods-Lecture VI: Applying Newton’s Method Trevor Gallen Fall, 2015 1 / 40

Transcript of Numerical Methods-Lecture VI: Applying Newton's Method

Page 1: Numerical Methods-Lecture VI: Applying Newton's Method

Numerical Methods-Lecture VI:Applying Newton’s Method

Trevor Gallen

Fall, 2015

1 / 40

Page 2: Numerical Methods-Lecture VI: Applying Newton's Method

Motivation

I We’ve seen the theory behind Newton’s Method

I How can we apply it to Value Function Iteration?

I Solving systems of equations

I Maximization!

I Caveat: we’ll linearly interpolate for now.

2 / 40

Page 3: Numerical Methods-Lecture VI: Applying Newton's Method

Monopolistic Competition-IWe might have a system of equations describing agent behavior. Given elasticity ofsubstitution σ, Income I , marginal cost of production φ, and fixed cost of entry ν, amonopolistically competitive system’s equilibrium is given by:

I Consumption aggregation

C =

(∫ n

0c

σ−1σ

i di

) σσ−1

(1)

I Idiosyncratic demand curves:

ci =Ip−σ

i∫ n0 p1−σ

i di(2)

I Aggregate price:

P =

∫ n

0

(p1−σi di

) 11−σ

(3)

I Profit definition:πi = pici − φci − ν (4)

I Zero profit (free entry):πi = 0 (5)

I Optimal markup:

pi =σ

σ − 1φ (6)

3 / 40

Page 4: Numerical Methods-Lecture VI: Applying Newton's Method

Monopolistic Competition-II

I We won’t bother simplifying, though we can in this case.

I We want to solve these six equations as a function ofn, pi ,P, ci ,C , πi , and we’ll assume a symmetric equilibrium.

I To solve, we’ll:

I Step 1: Write all FOC’s as a vectorized function of those sixvariables

I Step 2: Write the Jacobian of the vector of FOC’s as afunction of those six variables

I Step 3: Apply Newton’s Method until we converge

4 / 40

Page 5: Numerical Methods-Lecture VI: Applying Newton's Method

Monopolistic Competition-III

For code, see Lecture 6 NewtonsMethod DixitStiglitz.m

5 / 40

Page 6: Numerical Methods-Lecture VI: Applying Newton's Method

Alternative Use of Newton’s Method:Estimation

I Linear regression of the type:

yi = Xiβ + εi

is easy. (Where y is an n × 1, Xi is an n × j , β is a j × 1, and

εi is a n × 1 matrix).

I β = (X ′X )−1X ′Y

I What if we had a slightly different problem? (Nonlinear leastsquares, for instance).

I Newton’s method helps us find a minimum.

6 / 40

Page 7: Numerical Methods-Lecture VI: Applying Newton's Method

Some Data

City Crack Index Crime Index

Baltimore 1.184 1405Boston 3.129 835Dallas 2.103 675Detroit 2.057 2123Indianapolis 0.858 1186Philadelphia 4.087 1160

7 / 40

Page 8: Numerical Methods-Lecture VI: Applying Newton's Method

Some Data

I Given β =

[00

]we can calculate εi :

εi =

1.183.132.102.060.864.09

1 14051 8351 6751 21231 11861 1160

[

00

]

I We can try to minimize∑ε2i .

8 / 40

Page 9: Numerical Methods-Lecture VI: Applying Newton's Method

In Matlab

I I assume all the data is already in Y and X as it is listed.

f = (beta) sum((y-X’*beta).^2)

d1 = [d,0]

d2 = [0,d]

d3 = [d,d]

f grad = (beta) [f([b(1)+d;b(2)]-f(b))/d ;

f([b(1);b(2)+d]-f(b))/d]

f hess = (b) [(f(b+d1)-2.*f(b)+f(b-d))/d ,

f(b+d3)-f(b+d1-d2)-f(b-d1+d2)+f(b-d3) ;

f(b+d3)-f(b+d1-d2)-f(b-d1+d2)+f(b-d3) ;

f(b+d2)-2*f(b)-f(b-d2)]/d^2

9 / 40

Page 10: Numerical Methods-Lecture VI: Applying Newton's Method

In Matlab

For code, see Lecture 6 NewtonsMethod LinReg.m

10 / 40

Page 11: Numerical Methods-Lecture VI: Applying Newton's Method

Initial Conditions

11 / 40

Page 12: Numerical Methods-Lecture VI: Applying Newton's Method

Step 1

12 / 40

Page 13: Numerical Methods-Lecture VI: Applying Newton's Method

...next step

13 / 40

Page 14: Numerical Methods-Lecture VI: Applying Newton's Method

...next step

14 / 40

Page 15: Numerical Methods-Lecture VI: Applying Newton's Method

...next step

15 / 40

Page 16: Numerical Methods-Lecture VI: Applying Newton's Method

...next step

16 / 40

Page 17: Numerical Methods-Lecture VI: Applying Newton's Method

...next step

17 / 40

Page 18: Numerical Methods-Lecture VI: Applying Newton's Method

...next step

18 / 40

Page 19: Numerical Methods-Lecture VI: Applying Newton's Method

...next step

19 / 40

Page 20: Numerical Methods-Lecture VI: Applying Newton's Method

...next step

20 / 40

Page 21: Numerical Methods-Lecture VI: Applying Newton's Method

...next step

21 / 40

Page 22: Numerical Methods-Lecture VI: Applying Newton's Method

...next step

22 / 40

Page 23: Numerical Methods-Lecture VI: Applying Newton's Method

...next step

23 / 40

Page 24: Numerical Methods-Lecture VI: Applying Newton's Method

...next step

24 / 40

Page 25: Numerical Methods-Lecture VI: Applying Newton's Method

...next step

25 / 40

Page 26: Numerical Methods-Lecture VI: Applying Newton's Method

...next step

26 / 40

Page 27: Numerical Methods-Lecture VI: Applying Newton's Method

...next step

27 / 40

Page 28: Numerical Methods-Lecture VI: Applying Newton's Method

...next step

28 / 40

Page 29: Numerical Methods-Lecture VI: Applying Newton's Method

...next step

29 / 40

Page 30: Numerical Methods-Lecture VI: Applying Newton's Method

...next step

30 / 40

Page 31: Numerical Methods-Lecture VI: Applying Newton's Method

...next step

31 / 40

Page 32: Numerical Methods-Lecture VI: Applying Newton's Method

...next step

32 / 40

Page 33: Numerical Methods-Lecture VI: Applying Newton's Method

...next step

33 / 40

Page 34: Numerical Methods-Lecture VI: Applying Newton's Method

...next step

34 / 40

Page 35: Numerical Methods-Lecture VI: Applying Newton's Method

...next step

35 / 40

Page 36: Numerical Methods-Lecture VI: Applying Newton's Method

...next step

36 / 40

Page 37: Numerical Methods-Lecture VI: Applying Newton's Method

...next step

37 / 40

Page 38: Numerical Methods-Lecture VI: Applying Newton's Method

...next step

38 / 40

Page 39: Numerical Methods-Lecture VI: Applying Newton's Method

28th step...

39 / 40

Page 40: Numerical Methods-Lecture VI: Applying Newton's Method

Last step!

Note: took about 863 steps to get both gradients to < 10−10. 40 / 40