cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X

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

KN_9565343
4-Participant

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

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.

ACCEPTED SOLUTION

Accepted Solutions
Werner_E
25-Diamond I
(To:KN_9565343)

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

 

 

 

View solution in original post

2 REPLIES 2
Werner_E
25-Diamond I
(To:KN_9565343)

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

 

 

 

KN_9565343
4-Participant
(To:Werner_E)

Thank you so much, Werner. I appreciate it.

Announcements

Top Tags