[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Random number function for normal distribution?
From: |
Gorazd Brumen |
Subject: |
Re: Random number function for normal distribution? |
Date: |
Tue, 17 Oct 2006 22:59:21 +0200 |
User-agent: |
Thunderbird 1.5.0.7 (X11/20060921) |
Hi,
Btw, since the question has popped up,
attached is a way to generate a random normal vector. I
did not write it nicely, but perhaps somebody can use include it
in the functions below.
Regards,
Gorazd
%% simulates number of times from a normal distribution
%% with mean mu and variance-covariance matrix S,
%% mu has to be a vector
function res = simulate (mu, S, number)
prsize = rows (mu);
A = sqrtm (S);
b = A\mu;
for ind1 = 1:prsize
res(ind1,:) = normal_rnd (b (ind1), 1, 1, number);
endfor
res = A * res;
endfunction
Doug Stewart wrote:
> jian Xu wrote:
>> In MATLAB, I can use normrnd( mu, sigma, m, n) to generate a m by n
>> matrix with random number from the Normal(mu, sigma) distribution.
>> What is the corresponding function in Octave?
>>
>> More importantly, what is the best resource for me to look for answers
>> of this kind of question? Thank you very much.
>>
>> Jian
>> _______________________________________________
>> Help-octave mailing list
>> address@hidden
>> https://www.cae.wisc.edu/mailman/listinfo/help-octave
>>
>>
>
>
> This should be what you want.
>
> _Function File:_ *normal_cdf* /(x, m, v)/
> For each element of x, compute the cumulative distribution function
> (CDF) at x of the normal distribution with mean m and variance v.
>
> Default values are m = 0, v = 1.
>
> @anchor{doc-normal_inv}
>
> _Function File:_ *normal_inv* /(x, m, v)/
> For each element of x, compute the quantile (the inverse of the CDF)
> at x of the normal distribution with mean m and variance v.
>
> Default values are m = 0, v = 1.
>
> @anchor{doc-normal_pdf}
>
> _Function File:_ *normal_pdf* /(x, m, v)/
> For each element of x, compute the probability density function
> (PDF) at x of the normal distribution with mean m and variance v.
>
> Default values are m = 0, v = 1.
>
> @anchor{doc-normal_rnd}
>
> _Function File:_ *normal_rnd* /(m, v, r, c)/
> Return an r by c matrix of random samples from the normal
> distribution with parameters m and v. Both m and v must be scalar or
> of size r by c.
>
> If r and c are omitted, the size of the result matrix is the common
> size of m and v.
>
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://www.cae.wisc.edu/mailman/listinfo/help-octave
>
--
Gorazd Brumen
Mail: address@hidden
WWW: http://www.gorazdbrumen.net/
PGP: Key at http://pgp.mit.edu, ID BCC93240