0% found this document useful (0 votes)
2 views

Assignment_tuesday

The assignment involves simulating draws from a unique probability distribution to illustrate the Central Limit Theorem, solving a nonlinear equation using Newton's method, and addressing a functional equation through time iteration. Students are required to derive the cumulative distribution function, calculate statistical measures, and graph results. In each task, incomplete scripts are provided to assist in the numerical computations and visualizations.

Uploaded by

tianfei.lyu.163
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Assignment_tuesday

The assignment involves simulating draws from a unique probability distribution to illustrate the Central Limit Theorem, solving a nonlinear equation using Newton's method, and addressing a functional equation through time iteration. Students are required to derive the cumulative distribution function, calculate statistical measures, and graph results. In each task, incomplete scripts are provided to assist in the numerical computations and visualizations.

Uploaded by

tianfei.lyu.163
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Numerical Methods Bootcamp

Tuesday Assignment
Miscellaneous stuff

In this assignment you are asked to do three things. First, you will simulate draws from
a weird probability distribution and illustrate the Central Limit Theorem.1 Second you
are asked to solve a nonlinear equation on a grid containing several values of a parameter,
numerically approximate the solution for parameter values not on the grid, and graphically
illustrate the results. Lastly, you will solve a fixed point problem. As usual you are provided
with some incomplete scripts to get you started.

The Central Limit Theorem in action. Consider the probability density function
(pdf)

f (x) = a(1 − x), if x ≥ x̄


f (x) = 0, otherwise.

for x ∈ [0, 1]. Figure 1 illustrates what this pdf looks like. In Figure 1 (and the subsequent
figures) x̄ is set to 0.7 and a = 1/(1/2+1/2x̄2 − x̄). Can you verify that this indeed is a pdf?
Derive the cdf, F (z) = P r(x ≤ z), and its inverse. Figure 2 illustrates what these should
look like. The inverse of a cdf is incredibly useful for the purpose of simulating peculiar
looking distributions.
Calculate the mean, µ, and the variance, σ 2 , of the distribution using the integral
function in Matlab.
Set the random seed to 1979 and make N = 100 draws of a random uniform variable on
[0, 1]. Calculate Sn as
√ −1 (e
P
iF i)
Sn = N( − µ).
N
Repeat 10,000 times and plot a histogram. Figure 3 shows the results you should get, ac-
companied by a fitted normal distribution. According to the CLT, limN →∞ Sn should be
normally distributed with mean µ and variance σ 2 . Isn’t the CLT pretty damn amazing
after all? What happens if you set N = 2?

1
This may seem slightly divorced from the course content. But it is a useful exercise to illustrate how
numerical computations can provide some intuition on theoretical results. Seeing is believing.
2

Probability Density Function


7

5
Density

0
0 0.2 0.4 0.6 0.8 1
Support, x

Figure 1. Probability Density Function (pdf).

Cumulative Distribution Function Cumulative Distribution Function


1.2 1

1 0.95
Cumulative distribution

0.9
0.8
Support, x

0.85
0.6
0.8
0.4
0.75
0.2 0.7

0 0.65
0 0.5 1 0 0.5 1
Support, x Cumulative distribution

Figure 2. Cumulative Density Functions (cdf).


3

Histogram vs. Probability Density Function


6

4
Density

0
0.5 0.6 0.7 0.8 0.9 1 1.1
Support, x

Figure 3. Histogram with fitted normal.

A nonlinear equation. The nonlinear equation you will solve is given by

f (y) = (xη − y)−1 − δηy η−1 (y η − z)−1 ,

where x and z are treated as parameters. z is set equal to (ηδ)1/(1−η) .


For each value of x on a grid solve for y such that f (y) = 0 using Newton’s method.
Plot your results in the (x, y) plane. Compare your results with those in Figure 4 which
illustrates the mapping y = g(x). That is the function y = g(x) such that,

(xη − g(x))−1 − δηg(x)η−1 (g(x)η − z)−1 = 0 ∀x

What is the relationship between z and the intersection of your solution with the 45o line?

A Functional Equation. For this exercise we will think of z as being an endogenous


variable which relates to y in exactly the same way as y relates to x. That is if y = g(x)
then z = g(y), or, equivalently, that z = g(g(x)). As a consequence, the function g(x)
should satisfy the functional equation

(xη − g(x))−1 − δηg(x)η−1 (g(x)η − g(g(x)))−1 = 0 ∀x (1)


4

0.22
0.21
0.2
Solution, y

0.19
0.18
0.17
0.16 Solution
Initial guess
0.15 450 line
0.14
0.14 0.16 0.18 0.2 0.22 0.24
Grid for x

Figure 4. The solution to a nonlinear equation.

Notice that the only difference between this equation and the previous equation is that z is
now not fixed, but a function of y. And it takes the same for as y as a function of x. Hence,
z is replaced by g(g(x)).
There are several ways of solving this functional equation, but I would like you to use
what is known as time iteration – a concept that will be further clarified tomorrow.
Time iteration in this setting works as follows. Guess for a solution to equation (1)
and call this guess g0 (·). For instance, a stupid, but perfectly operational guess, would be
g0 (x) = x.2 Now, use your knowledge of solving nonlinear equations on a grid for x to solve

(xη − y)−1 − δηy η−1 (y η − g0 (y))−1 = 0 ∀x

Thus, for all x we have a solution for y. Combining these solutions we can use an ap-
proximation method to update our guess y = g1 (x). Thus, in general, for any guess gn (x),
solve

(xη − y)−1 − δηy η−1 (y η − gn (y))−1 = 0

for a grid of x. Combine to create y = gn+1 (x), and repeat until

(xη − gn (x))−1 − δηgn (x)η−1 (gn (x)η − gn (gn (x)))−1 ≈ 0, ∀x.

2This is not a general statement. It is a good idea to choose an initial guess with a bit of care.
5

If you have done things correctly, your results should correspond to Figure 5

0.22
0.21
0.2
Solution, y

0.19
0.18
0.17
Solution
0.16 Initial guess
450 line
0.15 Exact solution
0.14
0.14 0.16 0.18 0.2 0.22 0.24
Grid for x

Figure 5. The solution to a functional equation.

You might also like