how to write the randn' s code with just using rand and CLT
Show older comments
I wrote this code but I didn't get the correct answer from it. i don't know where the problem is. thank for help
clc
clear all
m = input( 'please enter the number of LINES:');
n = input( 'please enter the number of ROWS:');
y = zeros(m,n);
G = zeros(m,n);
x = rand(m,n);
y= 0.2*x+32;
s(1)=y(1);
s(m*n)=sum(sum(y));
for i= 3: m*n
s(i-1)= s(i-2) + y(i-1);
end
G = zeros(m,n);
for i= 1:m*n
G(i) = s(i)/(i) ;
end
disp(G)
hist(G)
4 Comments
Walter Roberson
on 19 Feb 2016
What is CLT in this context?
I think your problem might be that rand generates numbers uniformly on [0,1]. I'm not at all clear what is going on with your code here, since it seems to be doing something specific, and not generally solving the problem, but you need to use rand to produce a variable with the same mean and variance. If you don't have that, you can't get anywhere in the first place. For instance, y here has mean 32.1 and variance of like approx 0.2/12
I'm assuming you directly want to do this using the CLT, and not just use the inverse of the normal CDF? Because that's way easier.
alireza kooshafar
on 19 Feb 2016
jgg
on 19 Feb 2016
If you don't care about the method, see the answer below.
Accepted Answer
More Answers (0)
Categories
Find more on Interpolation 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!