R code to matlab, or simply generating a zero mean gaussian and finding the covariance matrix

์กฐํšŒ ์ˆ˜: 1 (์ตœ๊ทผ 30์ผ)
Samah Salha
Samah Salha 2021๋…„ 2์›” 24์ผ
๋Œ“๊ธ€: Samah Salha 2021๋…„ 2์›” 26์ผ
I have the following code in R that finds the covariance matrix for the (bivariate) random vector [Generate 5,000 samples of a zero-mean Gaussian rv ๐‘ฅ โˆผ ๐‘(0,1)Then, generate the second rv ๐‘ฆ by the equation ๐‘ฆ = 0.5๐‘ฅ + ๐‘ฃ where ๐‘ฃ โˆผ ๐‘(0,0.3).] I would like to do same in Matlab, How?
x=norm(5000,0,1)
y=norm(5000,0,0.3)
y=0.5*x+v
cov=mean(x*y)-(mean(x)*mean(y))
cov
s=cov*(sqrt(var(x)))*(sqrt(var(y)))
c=matrix(c(var(x),s,s,var(y)),nrow=2)
c

์ฑ„ํƒ๋œ ๋‹ต๋ณ€

Jeff Miller
Jeff Miller 2021๋…„ 2์›” 24์ผ
x=normrnd(0,1,5000,1);
v=normrnd(0,0.3,5000,1);
y=0.5*x+v;
cov=mean(x.*y)-(mean(x)*mean(y));
cov
s=cov*(sqrt(var(x)))*(sqrt(var(y)))
c= [var(x) s; s var(y)];
c
  ๋Œ“๊ธ€ ์ˆ˜: 1
Samah Salha
Samah Salha 2021๋…„ 2์›” 26์ผ
Thanks!

๋Œ“๊ธ€์„ ๋‹ฌ๋ ค๋ฉด ๋กœ๊ทธ์ธํ•˜์‹ญ์‹œ์˜ค.

์ถ”๊ฐ€ ๋‹ต๋ณ€ (0๊ฐœ)

์นดํ…Œ๊ณ ๋ฆฌ

Help Center ๋ฐ File Exchange์—์„œ ANOVA์— ๋Œ€ํ•ด ์ž์„ธํžˆ ์•Œ์•„๋ณด๊ธฐ

Community Treasure Hunt

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

Start Hunting!

Translated by