It appears that you're asking how to generate data with a particular correlation matrix.
A useful fact is that if you have a random vector ${\bf x}$ with covariance matrix $\Sigma$, then the random vector ${\bf Ax}$ has mean ${\bf A} E({\bf x})$ and covariance matrix $ \Omega = {\bf A} \Sigma {\bf A}^{T} $. So, if you start with data that has mean zero, multiplying by ${\bf A}$ will not change that, so your first requirement is easily satisfied.
Let's say you start with (mean zero) uncorrelated data (i.e. the covariance matrix is diagonal) - since we're talking about the correlation matrix, let's just take $\Sigma = I$. You can transform this to data with a given covariance matrix by choosing ${\bf A}$ to be the cholesky square root of $\Omega$ - then ${\bf Ax}$ would have the desired covariance matrix $\Omega$.
In your example, you appear to want something like this:
$$ \Omega = \left( \begin{array}{ccc}
1 & .8 & 0 \\
.8 & 1 & .8 \\
0 & .8 & 1 \\ \end{array} \right) $$
Unfortunately that matrix is not positive definite, so it cannot be a covariance matrix - you can check this by seeing that the determinant is negative. Perhaps, instead
$$ \Omega = \left( \begin{array}{ccc}
1 & .8 & .3 \\
.8 & 1 & .8 \\
.3 & .8 & 1 \\ \end{array} \right) \ \ \ \ {\rm or} \ \ \ \Omega = \left( \begin{array}{ccc}
1 & 2/3 & 0 \\
2/3 & 1 & 2/3 \\
0 & 2/3 & 1 \\ \end{array} \right)$$
would suffice. I'm not sure how to calculate the cholesky square root in matlab (which appears to be what you're using) but in R
you can use the chol()
function.
In this example, for the two $\Omega$s listed above the proper matrix multiples(respectively) would be
$$ {\bf A} = \left( \begin{array}{ccc}
1 & 0 & 0 \\
.8 & .6 & 0 \\
.3 & .933 & .1972 \\ \end{array} \right) \ \ \ \ {\rm or} \ \ \ {\bf A} = \left( \begin{array}{ccc}
1 & 0 & 0 \\
2/3 & .7453 & 0 \\
0 & .8944 & .4472 \\ \end{array} \right)$$
The R
code used to arrive at this was:
x = matrix(0,3,3)
x[1,]=c(1,.8,.3)
x[2,]=c(.8,1,.8)
x[3,]=c(.3,.8,1)
t(chol(x))
[,1] [,2] [,3]
[1,] 1.0 0.0000000 0.0000000
[2,] 0.8 0.6000000 0.0000000
[3,] 0.3 0.9333333 0.1972027
x[1,]=c(1,2/3,0)
x[2,]=c(2/3,1,2/3)
x[3,]=c(0,2/3,1)
t(chol(x))
[,1] [,2] [,3]
[1,] 1.0000000 0.0000000 0.0000000
[2,] 0.6666667 0.7453560 0.0000000
[3,] 0.0000000 0.8944272 0.4472136