How can I employ Monte Carlo simulation?
Show older comments
How can I write a MATLAB code that generates B = 10000 i.i.d. realizations of zT and tT for sample sizes T = 10, 20, 40, 80, 160. Set the true values to α0 ∈ {−0.8, 0.0, 0.8} and λ = 1.
1 Comment
Rena Berman
on 1 Jun 2020
(Answers Dev) Restored edit
Answers (1)
Image Analyst
on 16 May 2020
0 votes
I'm not sure what "Set the true values to α0 ∈ {−0.8, 0.0, 0.8} and λ = 1" means. What are the "true values" which have values of true/false or 1/0?
For what it's worth, I'm attaching some Monte Carlo simulations.
10 Comments
Ulvu Mustafayev
on 16 May 2020
Image Analyst
on 16 May 2020
So how are we supposed to use them?
Ulvu Mustafayev
on 16 May 2020
Image Analyst
on 16 May 2020
We have absolutely no idea because the description is incomplete. The best I can come up with is this:
B = 10000
T = [10, 20, 40, 80, 160]
for b = 1 : B
for k = 1 : length(T)
numSamples = T(k);
zT = rand(numSamples, 1);
tTT = rand(numSamples, 1);
% Set the "true" values to α0 ∈ {−0.8, 0.0, 0.8} and λ = 1.
alpha0 = [-0.8, 0.0, 0.8];
lambda = 1;
end
end
but I know it's wrong. However I can't improve it until you explain it better.
Image Analyst
on 17 May 2020
Edited: Image Analyst
on 17 May 2020
No, no emai - I'm not a private consultant. Anything should be able to be public here for everyone to benefit from. Besides, I doubt your instructor would think it was okay for you to turn in my answer as your own would he? Most academic places don't allow that. So I gave you a start. I've marked it as homework on the tag on the right side of this page. Basically Monte Carlo all revolves around getting a set of random numbers and running some experiment millions of times to get some kind of distribution. So why don't you read this link, then post your code (not mine) and we'll give you hints on how to correct it.
What is wt? Is that w(t) which is w as a function of t? What is lambda? I don't see it in any of your formulas. Obviously you teacher discussed some things that I don't know about and you have not shared with us. Is lambda what's normally called sigma - the standard deviation of a Gaussian? Have you looked at randn() to get Gaussian distributed numbers?
Ulvu Mustafayev
on 17 May 2020
Edited: Image Analyst
on 17 May 2020
Image Analyst
on 17 May 2020
OK, but still I don't know how. But I can help you with getting randn() or normrnd() to work. How did you call it?
Ulvu Mustafayev
on 17 May 2020
Image Analyst
on 17 May 2020
Generate a 1-by-N row vector of normally distributed random numbers. Here's a little demo.
%----------------------------------------------------------------------------
% Draw random numbers from a Guassian distribution.
N = 1000000; % Number of points.
mu = 10; % Mean
sigma = 5; % Standard deviation.
% Draw a million numbers with a mean of mu, and a standard deviation of sigma.
r = sigma * randn(1, N) + mu;
%----------------------------------------------------------------------------
% Show histogram.
histogram(r);
grid on;
fontSize = 20;
xlabel('r Value', 'FontSize', fontSize);
ylabel('Count', 'FontSize', fontSize);
% Verify what we actually got:
rMean = mean(r)
rStdDev = std(r);
caption = sprintf('Histogram. Actual Sample Mean = %f Actual Sample StDev = %f', rMean, rStdDev);
title(caption, 'FontSize', fontSize);
% Maximize figure window
g = gcf;
g.WindowState = 'maximized';

Ulvu Mustafayev
on 17 May 2020
Categories
Find more on Axes Transformations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!