Basics
Excel Functions for Linear Algebra
2023-12-13
1. Introduction of Excel functions for Linear Algebra
Understanding machine learning algorithms in Excel requires familiarity with linear algebra and the corresponding worksheet functions. The following sections introduce Excel functions used in linear algebra.
Sum of a vector components = SUM
Arithmetic mean of a vector components = AVERAGE
Variance of a vector components = VAR.P
Covariance of two vectors = COVARIANCE.P
Magnitude of a vector = SUMSQ
Inner product of two vectors (dot product) = SUMPRODUCT
The product of the sum of the differences between two vectors = SUMXMY2.
Matrix multiplication = MMULT
Matrix transpose = TRANSPOSE
Matrix inversion = MINVERSE
2. Vector Basics
In Excel, a vector is a sequence of numbers represented as a one-dimensional form, either as a single row or a single column.
A matrix is a collection of two-dimensional numbers that are simultaneously included in rows and columns.
The product function of vectors, SUMPRODUCT, represents the sum of the products of each corresponding pair of elements (either one-dimensional or two-dimensional) with the same dimensions, resulting in a single number.

\(\text{SUMSQ}(\mathbf{a})=(a_1^2+a_2^2+a_3^2+\cdots +a_n^2)\)
\(\text{SUMPRODUCT}(\mathbf{a},\mathbf{b})=(a_1b_1+a_2b_2+a_3b_3+\cdots a_nb_n)\)
\(\text{SUMXMY2}(\mathbf{a},\mathbf{b})=(a_1-b_1)^2+(a_2-b_2)^2+(a_3-b_3)^2+\cdots (a_n-b_n)^2\)
The size (n) and shape (row or column, or matrix) of vectors a and b must be the same.
2.1 Inner product = SUMPRODUCT(a,b)
Inner product of two vectors a and b is the sum of the paired component wise multiplication. Their numbers of components must be same.
\(a \cdotp b = (a_1b_1+a_2b_2+a_3b_3+a_4b_4,\cdots,a_nb_n)\)

3. Matrix Basics
To be able to multiply two matrices, the dimensions must satisfy the following condition: the number of columns in the first matrix must be equal to the number of rows in the second matrix. In other words, if matrix A is [nxm] and matrix B is [ixj], then MMULT(A, B) is only possible if m=i, and the result will be [nxj].
The MINVERSE function is applicable only to square matrices, which means matrices with an equal number of rows and columns.
When using functions for matrices, you need to use the Array function.
After selecting the cell corresponding to the size of the desired result, you can enter the function and execute it by using Shift+Ctrl+Enter to display all the results in the cell at once.
3.1 Multiplication of two Matrix A and B =MMULT(A,B)
The number of columns of the first Array A must be equal to the number of rows of the 2nd Array B to perform a matrix multiplication.
\(A=\begin{bmatrix} 1 & 0 \\ -3 & 2 \end{bmatrix} \)
\(B=\begin{bmatrix} -1 & 4\\ 3 & 5 \end{bmatrix} \)

\((A \cdotp B) = \begin{bmatrix}-1 & 4 \\ 9 & -2 \end{bmatrix} \)
3.2 Transpose Matrix = TRANSPOSE(A)
\(A=\begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \end{bmatrix} \)
\(A^T=\begin{bmatrix} 1 & 4 \\ 2 & 5 \\ 3 & 6 \end{bmatrix} \)
3.3 Inverse Matrix = MINVERSE(A)
\(A=\begin{bmatrix} 4 & 7 \\ 2 & 6 \end{bmatrix} \)
\(A^{-1}=]\dfrac {1}{4*6-7*2}\begin{bmatrix} 6 & -7 \\ -2 & 4 \end{bmatrix}=\dfrac {1}{10}\begin{bmatrix}6 & -7 \\ -2 & 4 \end{bmatrix}\)
MINVERSE(A)=A-1=\(\begin{bmatrix} 0.6 & -0.7 \\ -0.2 & 0.4 \end{bmatrix}\)
When dealing with matrices in Excel, you use Array Functions. Specifically, (1) select the cells that match the size of the desired result, (2) enter the function, and (3) execute it by pressing Shift+Ctrl+Enter to output all the results in the cells at once.