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
then you will get
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;
will return
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,
will return
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
then you will get
since (1· 1 + 3· 2)/(1+2) = 7/3 and (2· 2 + 4· 1)/(2 + 1) = 8/3.