MATLAB Answers

How can we create two vectors have normally distributed random entries with zero mean?

1 ビュー (過去 30 日間)
Omar B.
Omar B. 2019 年 9 月 8 日
編集済み: Omar B. 2019 年 9 月 12 日
How can we create two vectors have normally distributed random entries with zero mean , and they are scaled so that in Matlab.

  0 件のコメント

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

採用された回答

Bruno Luong
Bruno Luong 2019 年 9 月 8 日
I correct the flaw of dpb method
U=randn(10,1);
V=randn(10,1);
ps=U.'*V;
a=sqrt(abs(ps));
U=(sign(ps)/a)*U;
V=(1/a)*V;

  1 件のコメント

dpb
dpb 2019 年 9 月 8 日
Ah! Good catch, Bruno! Thanks.

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

その他の回答 (1 件)

dpb
dpb 2019 年 9 月 8 日
>> uv=randn(1000,2);
>> uv=uv/sqrt(sum(uv(:,1).*uv(:,2)));
>> uv(:,1).'*uv(:,2)
ans =
1.0000
>> mean(uv)
ans =
0.0025 0.0091
>>

  4 件のコメント

表示 1 件の古いコメント
dpb
dpb 2019 年 9 月 8 日
uv(:,1) and uv(:,2) are vectors with such properties...just created them as an array--name them however you wish.
Bruno Luong
Bruno Luong 2019 年 9 月 8 日
the sqrt() might be imaginary (1/2 chance)
>> uv=randn(10,2); uv=uv/sqrt(sum(uv(:,1).*uv(:,2)))
uv =
0.0000 + 0.3856i 0.0000 + 0.0703i
0.0000 + 0.9468i 0.0000 - 1.0239i
0.0000 + 0.0416i 0.0000 - 0.9650i
0.0000 + 0.1552i 0.0000 + 0.0931i
0.0000 - 0.1422i 0.0000 + 0.4418i
0.0000 - 0.7345i 0.0000 + 1.1256i
0.0000 - 0.4265i 0.0000 - 0.4973i
0.0000 - 0.9666i 0.0000 - 0.0169i
0.0000 + 0.5398i 0.0000 + 0.8718i
0.0000 + 0.6400i 0.0000 + 0.2477i
John D'Errico
John D'Errico 2019 年 9 月 8 日
Normally distributed, with zero mean. You don't say if the sample mean should be zero, or the population mean zero. Normal samples from randn have a zero popiulation mean. But the sample mean just has an expected value of zero. A subtle difference that few people seem to appreciate when they lack the proper background.
Anyway, it is easy enough to scale them so the dot product is also 1. I could keep them as separate vectors, since that seems to have confused you, but you need to LEARN TO USE MATRICES.
uv = randn(1000,2);
dp = uv(:,1)' * uv(:,2);
uv = uv/sqrt(abs(dp));
if dp < 0
uv(:,1) = -uv(:,1);
end
As you can see, the dot product is 1. Note that the code I gave you will not end up 50% of the time with an imaginary square root.
uv(:,1)'*uv(:,2)
ans =
1
mean(uv)
ans =
-0.00248985528111534 -0.00172138844051432
The sample means are not identically zero, but you were not specific there, and that is simply repaired.
Do you really think you need disrinctly named vectors? LEARN TO USE MATLAB! The mat in MATLAB stand for matrix.
u = uv(:,1);
v = uv(:,2);

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by