### 8.1.1 The mean: mean

Recall that the mean of a list x1,…,xn is simply their numeric average (x1 + ⋯ + xn)/n. Xcas can calculate the mean of a list of numbers with the mean command. If you enter

mean([1,2,3,4])

then you will get

5/2

since (1+2+3+4)/4 = 5/2. If you give mean a matrix as an argument, then it will return a list with the numeric average of each column;

mean([[1,2,3],[5,6,7]])

will return

[3,4,5]

since (1+5)/2 = 3, (2+6)/2 = 4 and (3 + 7)/2 = 5.

To get the weighted average of a list of numbers you can give mean a second argument, which should be a list of the weights. For example,

mean([2,4,6,8],[2,2,3,3])

will return

27/5

since (2· 2 + 4· 2 + 6· 3 + 8· 3)/(2 + 2 + 3 + 3) = 27/5. Similarly, you can find the weighted average of the columns of a matrix by giving mean a second argument of a matrix of weights. If you enter

mean([[1,2],[3,4]],[[1,2],[2,1]])

then you will get

[7/3,8/3]

since (1· 1 + 3· 2)/(1+2) = 7/3 and (2· 2 + 4· 1)/(2 + 1) = 8/3.