Assignment_tuesday
Assignment_tuesday
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)
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
5
Density
0
0 0.2 0.4 0.6 0.8 1
Support, x
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
4
Density
0
0.5 0.6 0.7 0.8 0.9 1 1.1
Support, x
What is the relationship between z and the intersection of your solution with the 45o line?
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
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
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
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