2.4 Vector Functions - sum, mean, median, var, std

When we type [] as a function argument, that argument is left undefined. If the argument has a default value, then the default value will be used for that undefined argument. This principle will be illustrated in the video. 

Play media comment.

 

Recall, that the (unbiased) sample variance is defined as:

LaTeX: \sigma^2_y = \frac{1}{N-1} \sum_{i=1}^{N} (y_i - \overline{y})^2σ2y=1N1Ni=1(yi¯y)2

where 

LaTeX: \overline{y} = \frac{1}{N} \sum_{i=1}^{N}y_i¯y=1NNi=1yi is the sample mean and where

LaTeX: y_1, y_2, ..., y_Ny1,y2,...,yN are observations (numbers) of the random variables LaTeX: Y_1, Y_2, ..., Y_NY1,Y2,...,YN.

In the video, we had the following matrix:

LaTeX: A = \begin{bmatrix}
10 & 1 & 7\\
1& 2& 3 \\ 
1 & 1 & 3
\end{bmatrix}A=[1017123113]

We view the first column as three observations of the first random variable, the second column as three observations of the second random variable and so on. For instance, the first column could be the number of fishes Kalle caught in a river, the second column could be the number of fishes Kalle caught in a lake and so on. 

We wrote the MATLAB code:

var(A, [], 1)  %a row vector containing the variance of each column, the weighting scheme is 0 by default, meaning we divide by number of observations (N) - 1. 

The answer we got was: [27.0000 0.3333 5.3333]. Let's do the calculation manually. 

So, N = 3, meaning that N-1 = 2. 

And doing the calculation for the first column yields: 

LaTeX: \sigma_{X}^2 = \frac{1}{3-1} \sum_{i=1}^{3} x_i^2  = \frac{1}{2} [(10 - 4)^2+ (1 - 4)^2 + (1 - 4)^2] = \frac{1}{2}[36 + 9 + 9] = \frac{1}{2}[54] = 27σ2X=1313i=1x2i=12[(104)2+(14)2+(14)2]=12[36+9+9]=12[54]=27

Where we used that 

LaTeX: \overline{y} = 4¯y=4


Perform the calculations for the second and third column to verify that MATLAB returns the correct answer.