Recently I am doing my math homework and there is a question asking me to Come up with a dataset X that has at least 10 distinct numbers in it such that Expect[X] = 3.7, and Var[X] = 2.1. Actually I did not know how to use Mathematica before, so I really have no idea how to generate. I read many sources and wrote a code
X=RandomVariate[NormalDistribution [3.7, Sqrt [2.1]], 10]
Unfortunately it does not work...Can anyone tell me what's wrong?
Thanks a lot!

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

What's wrong is that RandomVariate is going to give a random answer. The bigger the sample, the more likely that μ will be closer to 3.7 and σ will be closer to Sqrt[2.1].
–
Michael E2Jun 24 '13 at 0:35

What do you mean by "Unfortunately it does not work." ? What do you see as output?
–
belisariusJun 24 '13 at 0:59

@zzy I believe what you want is a set with exact mean and variance. I believe Mathematica won't produce what you want, once the RandomVariate[] function works better for a large set of random numbers...
–
RodJun 24 '13 at 1:07

If you are allowed to use a standard calculator, the point of the exercise is for you, by means of trial and error, to understand how changing a data value affects the mean and variance. (Otherwise, the point would also be to practice using the formulas for mean and variance.) Mathematica can solve the problem without you having to go through such an instructive process, but instead of showing you how to do that, I will show you tools for experimenting the way I think the problem intends you to do.

Enter this:

data = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

and this:

Dynamic @ N @ {Mean[data], Variance[data]}

{5.5, 9.16667}

Now change the numbers in the list for data and press shift-return. The mean and the variance will be automatically updated. Change data until you bring the mean and variance to the desired values. It may be hard to hit them exactly, but perhaps the book intends for you to find data such that mean and variance round off to the desired values.

Mathematica is a registered trademark of Wolfram Research, Inc. While the mark is used herein with the limited permission of Wolfram Research, Stack Exchange and this site disclaim all affiliation therewith.