I have a set of numbers $A=\lbrace a_1,a_2,a_3,...a_n \rbrace$

I want to find new numbers $X=\lbrace x_1,x_2,x_3,...x_n \rbrace$ such

  1. Mean

$$\mu(A )=\mu(X)$$

  1. Variance


  2. Correlation coefficient $$r_{AX}=k $$

Where $k$ is a some constant, $0<k<1$ .

each number $x_1(k),x_2(k)...x_n(k)$ depends only $k$,

How to solve this system of equations by using Mathematica?

for instance, $A=\lbrace 2,5,7 \rbrace$

and $k=0.7$

How to find $x_1,x_2,x_3?$

I tried first few steps:


list = {2,5,7}
X= {l, m, n}




$\frac{1}{3} (l+m+n)$




Refine[Variance[X], x \[Element] Reals]

$\frac{1}{6} (l (2 l-m-n)+m (-l+2 m-n)+n (-l-m+2 n))$

  • $\begingroup$ A related CV thread. $\endgroup$ Oct 10, 2016 at 18:00
  • $\begingroup$ As @J.M. notes, the linked question shows it's trivial to generate a set of numbers with a given mean and variance, but the tricky part here is getting the correlation to be exactly what you want. You could try randomly generating until you get close? $\endgroup$
    – user1722
    Oct 11, 2016 at 14:57

1 Answer 1


Like you said, this is just a system of equations, so we can use Solve to get solutions for the values of $X$:

list = {2, 5, 7};
X = {l, m, n};
k = .7;
Assuming[Element[X, Reals], Solve[Mean[list] == Mean[X] && 
    Simplify[Variance[list] == Variance[X]]] && Simplify[Correlation[list, X] == k], {l, m, n}]

Correlation is the Pearson correlation coefficient which ranges between -1 and 1, if you mean something else you can just use a different function for that.

If you only need to do this for sets with 3 elements as in your example this should do the trick. If there are also longer ones of the form {$a_1$, $a_2$,...,$a_n$} there is no unique solution since you have more unknowns than equations and you should be able to do something like choose random values for $n-3$ of the values in $X$ and then use Solve for the last 3.

  • $\begingroup$ thanks. but for example if list = {49, 25, 26, 5, 21, 47, 24} and x = {4, 6, 3, 1, l, m, t} and k=0.7 there is no real solution. How to choose $n-3$ random number to get a real solution? $\endgroup$
    – vito
    Oct 13, 2016 at 7:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.