Hi guys, I have two randomly generated variables and want to generate the third which is correlated with one of them and uncorrelated with the other. How can I generate such random variable?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Solomon Gofere
am 2 Nov. 2014
Kommentiert: Harry
am 2 Nov. 2014
To be specific I have these series
e~N(0,1)and x~N(0,v), where v is variance of x
and I want to generate another variable say Y that satisfy the following conditions
E(y,e) equal to zero E(Y,x) not equal to zero
Please help me out with this.
3 Kommentare
Harry
am 2 Nov. 2014
That's good - the answer I wrote should work for you. Please accept it if you are happy with it.
Akzeptierte Antwort
Harry
am 2 Nov. 2014
Bearbeitet: Harry
am 2 Nov. 2014
With problems like this, I always think it is easiest to start with zero-mean, unit-power uncorrelated random variables. It's difficult to write equations in this forum, so I wrote some which I have uploaded as an image at the end of this post. I assume you want real numbers, but this is straightforward to extend to the complex case.
First, here's the Matlab code:
close all; clear all; clc;
% Draw N random values for e
N = 10000;
e = randn(N,1);
% Set required variances and cross-correlation for x and y
Px = 1;
Py = 3;
rho_xy = 0.4;
% Generate s1 and s2 of length N
s1 = randn(N,1);
s2 = randn(N,1);
% Make x
x = sqrt(Px)*s1;
% Make y
B = rho_xy*sqrt(Py);
C = sqrt(Py*(1 - rho_xy^2));
y = B*x + C*s2;
% Check results
sample_Pe = mean(e.^2)
sample_Px = mean(x.^2)
sample_Py = mean(y.^2)
sample_rho_ey = e.'*y/(norm(e)*norm(y))
sample_rho_xy = x.'*y/(norm(x)*norm(y))
And here are the equations:

0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!