Skip to main content
4-Participant
January 18, 2024
Solved

Generate 10 samples of size 5 and obtain the mean of each sample

  • January 18, 2024
  • 1 reply
  • 1072 views

Kindly see the attached code. I would like to generate 10 samples of size 5. Then calculate the mean of each sample, so that I have 10 means.  However, my data contains only five elements. Obviously, something is wrong. Kindly assist.

Best answer by Werner_E

1) A program will return the last value, so in your case the last calculated y (for k=n). So you have to collect all values in a vector (using the vector index at y). And the last statement in the program must be "y" (or "return y") so that the whole vector is returned.

2) When you sum the elements of b you have to apply the index i if you use it on the sum. Otherwise the sum returns n-times the whole vector b and y will end up being the very same as vector b.

Werner_E_0-1705597754453.png

A bit easier (sum of a vector)

Werner_E_1-1705597159151.png

Even easier using the built-in "mean" function

Werner_E_2-1705597185181.png

And at last a tricky one using the "matrix" function

Werner_E_3-1705597212696.png

 

 

 

1 reply

Werner_E25-Diamond IAnswer
25-Diamond I
January 18, 2024

1) A program will return the last value, so in your case the last calculated y (for k=n). So you have to collect all values in a vector (using the vector index at y). And the last statement in the program must be "y" (or "return y") so that the whole vector is returned.

2) When you sum the elements of b you have to apply the index i if you use it on the sum. Otherwise the sum returns n-times the whole vector b and y will end up being the very same as vector b.

Werner_E_0-1705597754453.png

A bit easier (sum of a vector)

Werner_E_1-1705597159151.png

Even easier using the built-in "mean" function

Werner_E_2-1705597185181.png

And at last a tricky one using the "matrix" function

Werner_E_3-1705597212696.png

 

 

 

4-Participant
January 22, 2024

Thank you so much, Werner. I appreciate it.