generating a random variable with a given mean and matrix

can any one tell me how to generate a NORMAL DISTRIBUTION random variable X = N(mu,A), where mu is the mean (mu = 0, 0 mean) and A is a p*p IDENTITY MATRIX. Please ask me if the question is unclear. Thanks

 採用された回答

Image Analyst
Image Analyst 2016 年 10 月 15 日

0 投票

Like this?
numRows = size(A, 1);
A(logical(eye(numRows))) = randn(1, numRows)

8 件のコメント

fafz1203
fafz1203 2016 年 10 月 15 日
may I ask what the first line of command does?
fafz1203
fafz1203 2016 年 10 月 15 日
in my particular case A is 10*10 identity matrix
Image Analyst
Image Analyst 2016 年 10 月 15 日
The first line just figures out how large your square A matrix is. The second line assigns random numbers to elements along the diagonal only.
fafz1203
fafz1203 2016 年 10 月 15 日
that means i do not need the first line if i already know the size of my matrix right?
Image Analyst
Image Analyst 2016 年 10 月 15 日
編集済み: Image Analyst 2016 年 10 月 15 日
Correct. If you already know numRows, or whatever you call your variable, if you even use one, then you do not need to calculate it again. You can do this:
A(logical(eye(10))) = randn(1, 10)
fafz1203
fafz1203 2016 年 10 月 15 日
thanks
fafz1203
fafz1203 2016 年 10 月 15 日
I'm sorry but it turns out that I was wrong, Here is what I want to do I want to generate a random variable X (X~N(0,A)), that is it has 0 mean and A is a 10*10 covariance matrix which is a 10*10 identity matrix
now what i want to do is I want to generate a 10*1000 random variable X using the above information.
Please help me if you can. Thanks
Image Analyst
Image Analyst 2016 年 10 月 15 日
I don't believe you can do that and have the random variable be random. If it's random, you won't have A=eye(10) for the covariance matrix.

サインインしてコメントする。

その他の回答 (0 件)

タグ

タグが未入力です。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by