You are on page 1of 33

Page

1.

What is vMx? ..................................................................................................................................................................................................... 2

2.

Getting Started ..................................................................................................................................................................................................... 3

3.

2.1.

Installing vMx ....................................................................................................................................................................................................... 3

2.2.

Accessing vMx functions ....................................................................................................................................................................................... 3

2.3.

Using vMx: A First Example .................................................................................................................................................................................. 5

Array Formulas and vMx Ribbon ........................................................................................................................................................................... 8

4.

3.1.

Working with Array Formulas .............................................................................................................................................................................. 8

3.2.

Working with vMx Ribbon .................................................................................................................................................................................. 10

Operating on Matrices ........................................................................................................................................................................................ 16

5.

4.1.

Adding function VMX.ADD() ............................................................................................................................................................................... 16

4.2.

Subtraction function VMX.SUBTRACT() .............................................................................................................................................................. 17

4.3.

Multiplying function VMX.MULTIPLY() ............................................................................................................................................................... 17

4.4.

Dividing function VMX.DIVIDE() ......................................................................................................................................................................... 18

Matrix Decomposition ........................................................................................................................................................................................ 19

6.

5.1.

LU Decomposition ............................................................................................................................................................................................... 19

5.2.

QR Decomposition .............................................................................................................................................................................................. 20

5.3.

SVD and Matrix Rank .......................................................................................................................................................................................... 21

5.4.

Cholesky .............................................................................................................................................................................................................. 22

Eigen Values and Vectors .................................................................................................................................................................................... 23

7.

6.1.

Symmetric Examples ........................................................................................................................................................................................... 23

6.2.

Non-Symmetric Examples ................................................................................................................................................................................... 24

Solving Ax=b ....................................................................................................................................................................................................... 25

8.

7.1.

Square matrix ...................................................................................................................................................................................................... 25

7.2.

Symmetric Positive Definite ................................................................................................................................................................................ 25

7.3.

Non-Square ......................................................................................................................................................................................................... 26

Statistical Matrices ............................................................................................................................................................................................. 27

9.

8.1.

Co-Variance ......................................................................................................................................................................................................... 27

8.2.

Correlation .......................................................................................................................................................................................................... 28

8.3.

Standard deviation ............................................................................................................................................................................................. 29

Random and Diagonal Matrices .......................................................................................................................................................................... 30


9.1.

Random integer and real values Matrices ......................................................................................................................................................... 30

9.2.

Diagonal matrix .................................................................................................................................................................................................. 31

10.

Matrix Utilities .............................................................................................................................................................................................. 32


10.1.

Check if square matrix ........................................................................................................................................................................................ 32

10.2.

Check matrix symmetry ...................................................................................................................................................................................... 32

10.3.

Transpose a matrix ............................................................................................................................................................................................. 32

vMx: Microsoft Excel Linear Algebra Add-in

Page

1. What is vMx?
vMx is a free linear algebra Microsoft Excel add-In for operating, decomposing and solving matrices. vMx stands
for Vector Math in Excel. The Add-in consists of 45 functions and a Ribbon toolbar. Excel is one of the most
powerful tools for analyzing data but it does not offer much support for solving linear algebra problems. vMx
seeks to fill this void.
The vMx functions provide the following functionalities:

Decompose a Matrix A into LU, QR, Cholesky or SVD decomposition


Calculate the Eigen values or vector of a matrix
Solve linear equations for Ax=b for both square and non-square matrices
Add, subtract, divide or multiply up to 10 matrices with one function
Calculate the co-variance, correlation or standard-deviation matrix for a given data set
Create random matrices with integer or real numbers
Calculate matrix rank
Calculate matrix determinant
Transpose a matrix
Check if matrix type is square or symmetric
A Ribbon toolbar for working with array formulas

vMx: Microsoft Excel Linear Algebra Add-in

Page

2. Getting Started
vMx is a free Excel add-in that can be downloaded from the website www.vmxaddin.com. This pdf
document is also available on the website. This document contains sections explaining each vMx function
and the vMx Ribbon in detail.
2.1. Installing vMx
vMx is available as an add-in for Excel 2007 or 2010 . vMx can be installed on 32 or 64 bit systems.
However, vMx can only be installed on Excel 32 bit version. Excel 32 bit version can run on both 32 and 64
bit systems. Excel 64 bit version can run on 64 bit systems only. vMx was only tested on Windows 7 so no
assurances are given for any other Windows operating systems.
Once vMx is installed it will add a Ribbon under the Formula ribbon tab and to the right of the Function
Library menu items.

2.2. Accessing vMx functions


Once installed the vMx functions can be accessed in three ways:
1. Selecting Insert Function from the formula ribbon menu item, then you can filter by vMx under select a
category and select a vMx function.

vMx: Microsoft Excel Linear Algebra Add-in

Page

2. Type =VMX. into a cell and Excels auto complete functionality will list all the vMx available functions.

3. Use the vMx ribbon to bring up the vMx function list menu. The vMx ribbon can be found under the
formula ribbon menu item.

vMx: Microsoft Excel Linear Algebra Add-in

Page

2.3. Using vMx: A First Example


In this section we demonstrate using a vMx function. Generally the vMx functions are straightforward and
work just like any other Excel function such as VLOOKUP() or SUM(). The vMx functions take parameters or
inputs and return something. Most of the vMx functions return a matrix/array. A thorough understanding of
Excel array formula is imperative for working with the vMx functions. Section 2.4 covers working with Excel
array formulas. Throughout this document we use matrix or array interchangeably.
We define a matrix in Excel to be contiguous or adjacent cells containing only numbers. If a cell array
contains text strings then the vMx function will return an error. Also it is important to note that blank cells
in a cell array are read as zeros. In the example below cell range B2:C4 is a matrix but E2:F3 is not since it
contains a string character. H2:I4 is a matrix and H4 will be a zero value. K2:M4 is a matrix where range
M2:M4 and K4:M4 are zero values. Range O2:P4 is matrix with all zero values.

In our first example we use the vMx function VMX.TRANSPOSE() to transpose a matrix. If we want to
transpose the matrix [

] we can enter the values into Excel in range B2:C4

We then call the function using one of the three methods described in section 2.2. In this case we use the
second method and type directly in a cell.

vMx: Microsoft Excel Linear Algebra Add-in

Page

Now we can pass the address of our matrix to our function.

After we press enter the function transposes the matrix but at this point we can only see the element at row
1 column 1.

Since this the function returns an array we need to enter the formula into a cell range of 2 rows and 3
columns. For example, we can enter the formula into cell address E2:G3 as an array formula. We have two
options for entering a formula as an array formula. The first option is using Excels standard method and the
second (more efficient method) is with the vMx ribbon.
Option 1: (Excels standard method): Select the cell range (E2:G3) and then hoover the cursor over the
formula bar and left click. From this point we hold CTRL and SHIFT key at the same time and finally press
ENTER. This will display the formula result of VMX.TRANSOPSE(B2:C4) in the range E2:G3. Section 2.4
discusses using array formula in more detail. The formula bar will display opening and closing curly braces
around the formula.

After entering as a formula array:

Section 3.1 discusses array formula using excel standard method in more detail.

vMx: Microsoft Excel Linear Algebra Add-in

Page

Option 2 (using the vMx Ribbon): The vMx ribbon includes an Auto-Size Array button for resizing array formulas
to their proper size. For example after entering the transpose function into cell E2 we then select E2 and press
the Auto-Size Array button and it will automatically set the formula over cell range E2:G3 as a formula array.
Section 3.2 discusses using the vMx toolbar ribbon in more detail.

vMx: Microsoft Excel Linear Algebra Add-in

Page

3. Array Formulas and vMx Ribbon


In order to utilize the vMx functions its important to understand array formulas in Excel. The following two
sections discuss in detail using array formula with Excels standard method and the second with the vMx Ribbon
(Section 3.2).
3.1. Working with Array Formulas
In this section we cover creating and editing array formulas. The following is an excerpt from Microsoft
Website:
an array is just a collection of items. In Excel, those items can reside in a single row (called a onedimensional horizontal array), a column (a one-dimensional vertical array), or multiple rows and columns (a
two-dimensional array). You can't create three-dimensional arrays or array formulas in Excel.
An array formula is a formula that can perform multiple calculations on one or more of the items in an
array. Array formulas can return either multiple results or a single result. For example, you can place an
array formula in a range of cells and calculate a column or row of subtotals. You can also place a formula in a
single cell and calculate a single amount. An array formula that resides in multiple cells is called (logically
enough) a multi-cell formula, and an array formula that resides in a single cell is called a single-cell formula.
For our discussion we are concerned with multi-cell formula arrays. Most of the vMx functions return
arrays and thus the formula needs to be entered over multiple contiguous cells.
Entering Array Formulas
In section 2.3 we demonstrate a quick example using the VMX.TRANSPOSE() function and entering it as an
array formula.
Step 1: Enter the array formula into a cell.
Step 2: Select that same cell and highlight the additional adjacent cells.
Step 3: Put the cursor over the formula bar and left click the mouse to go into formula edit mode.
Step 4: Hold the CTRL & SHIFT simultaneously keys and press ENTER.
At this point the highlighted cells are treated as one group and the formula bar will put opening and closing
curly braces around the formula.
To re-demonstrate the example from section 2.3, where we want to transpose a 2 by 3 matrix using the
VMX.TRANSPOSE() function, we 1) enter the formula into cell E2 and 2) then highlight cells E2:G3, 3) left
click in formula and 4) CTRL + SHIFT + ENTER.

vMx: Microsoft Excel Linear Algebra Add-in

Page

After entering as an array formula:

Once you enter an array formula the included cells are treated as one group and can only be edited in
certain ways. If you try and change any of the included cells you will receive an error message.
Editing an Array Formula
To edit an array formula you first highlight the cells the array formula covers and then left-click the formula
bar. You can then edit the formula and finally press CTRL+SHIFT + ENTER. From our example above we
would highlight cells E2:G3, left-click the formula bar, edit the formula, and press CTRL+SHIFT + ENTER keys.
Removing an Array Formula
Excel does not provide an easy way to remove an array formula entered into multi-cells. However, the vMx
Ribbon which is discussed in section 3.2 makes it quite easy to remove array formulas. To remove an array
formula using the Excel built-in functionality you first highlight the array formula included cells, left-click the
formula bar, and hold CTRL and press ENTER. This will enter the same formula into all the highlighted cells.
From this point you can proceed to remove the formula from whichever cells you want. Fortunately, the
vMx Ribbon removes the formula except from the left top most element, which normally is what we want
when removing an array formula.

vMx: Microsoft Excel Linear Algebra Add-in

Page

10

3.2. Working with vMx Ribbon


The vMx Ribbon provides functionality for quickly accessing the vMx functions and for working with array
formulas. The vMx Ribbon will install under the Formula ribbon tab and to the right of the Function Library
menu items.

The vMx Ribbon contains four buttons and one check box. The following describes each item:

Function List: a menu item for


selecting all the available vMx
functions.

Override Prompt: check box that


works in tandem with the AutoSize Array button. If checked will
prompt the user if the Auto-Size
Array button will override any
adjacent cells that are nonblank.
Set Array: sets active cell range
with array formula. The formula
will be taken from the most
upper-top left cell.
Remove Array: will detect if the
active cell is part of an array
formula and will remove the
array formula. It will set the
most upper-top left cell with the
formula from array formula.
Auto-Size Array: reads the
formula from the active cell or
cells and will set the formula to
its proper array formula size.

vMx: Microsoft Excel Linear Algebra Add-in

Page

11

Function List.
When the user presses the vMx Function List button they will see a menu with all the available vMx functions.
The menu also has a function list filter to see available functions by category.

Selecting a function and pressing Insert will bring up the selected function to the Function Argument screen. On
this screen, the user can pass all the required function parameters.

vMx: Microsoft Excel Linear Algebra Add-in

Page

12

Auto-Size Array/Override Prompt


To demonstrate how to use the Auto-Size Array we use the same example from section 2.3. In section 2.3 we
gave an example where we transpose a matrix using the vMx function VMX.TRANSPOSE().

After entering the formula in cell E2 we need to enter the formula as an array formula over the range E2:G3.
Using the Auto-Size Array button will automatically perform setting E2:G3 with the formula from cell E2.

Now if we want to change our matrix and make it a 2 by 4 instead we will need to update our formula. To
update our formula we can click the insert function located to the left of the formula bar.

After clicking insert function we can update the input matrix range from B2:C4 to B2:C5 and then click the Ok
button.

vMx: Microsoft Excel Linear Algebra Add-in

Page

13

At this point our formula will update to the correct matrix input range but the array formula is still set to range
E2:G3 instead of E2:H3. To update the array formula, we select any cell in the range E2:G3 and press the AutoSize Array button. This will automatically resize our array formula to range E2:H3.

The Override Prompt check box works in tandem with the Auto-Size Array button. For example if cells H2 or H3
would have contained any value then in the above example, we would get a prompt that their content is about
to get replaced when pressing the Auto-Size Array button. The user will have the option to continue or cancel.
By default, Override Prompt is set to True but it can be disabled by unchecking it.

vMx: Microsoft Excel Linear Algebra Add-in

Page

14

Set Array Button.


The Set Array Button works similar to the Auto-Size Array button in that it sets an array formula over a range.
The biggest difference is that the Auto-Size Array button only sets array formulas to a range of cells only if the
formula function returns an array. In the example above the formula VMS.TRANSPOSE(B2:C5) returns an array
so the Auto-Size Array button can set it as an array formula. However, a formula such as =2+5 only returns one
value so the Auto-Size Array button will not set this formula as an array formula. With the Set Array button you
can take any formula (returns array or one value) and set the formula as an array formula over any size range of
cells. There are only two requirements with the Set Array button. First, the top most upper-left cell in the
selected range must contain a formula. Second, the selected range must be contiguous cells greater than a 1 by
1.
For example if we want to set the formula =2+5 as an array formula over a range we first enter the formula into
a cell and then starting with that same cell select a desired range. In the below example we enter the formula
into cell C3 and then highlight range C3:E7. Since C3 contains a formula and C3:E7 is greater than 1 by 1, we can
use the Set Array button.

Now after clicking the Set Array button cells C3:E7 are set with an array formula of =2+5

The Set Array button is a convenience feature to allow flexibility to the Auto-Size Array button.

vMx: Microsoft Excel Linear Algebra Add-in

Page

15

Remove Array Button.


The Remove Array button removes an array formula if the active cell is part of an array formula and puts the
formula into the top most upper-left cell.
To demonstrate the Remove Array functionality we use the transpose example from above where we set the
range E2:H3 with an array formula of VMX.TRANSPOSE(B2:C5). If we select any of the cells in the range E2:H3
and then press Remove Array button, it will remove the array formula. Additionally, we set cell E2 with the
formula VMX.TRANSPOSE(B2:C5) since it is the top most upper-left cell in the range.

After pressing Remove Array button.

vMx: Microsoft Excel Linear Algebra Add-in

Page

16

4. Operating on Matrices
There are four functions for adding, dividing, multiplying and subtracting matrices or scalars. The functions
can take up to 10 matrices or scalars but requires at least the first two parameters. With the exception that
multiplying all matrices passed as parameters must be of the same dimensions. All four functions return a
matrix if at least one parameter is a matrix. The four functions will return a scalar if all parameters passed
are scalar but if all parameters are scalar it is recommended to use the built-in Excel function SUM() instead.
The four functions are also left-to-right associative. The following table lists the four operating matrix
functions and the parameters they take.

Name
VMX.ADD()
VMX.DIVIDE()
VMX.MULTIPLY()
VMX.SUBTRACT()

Parameters
matrix A1,matrix A2,[matrix A3...matrix A10]
matrix A1,matrix A2,[matrix A3...matrix A10]
matrix A1,matrix A2,[matrix A3...matrix A10]
matrix A1,matrix A2,[matrix A3...matrix A10]

We use examples 4.1.1 through 4.4.2 in the sample vMx Excel file to demonstrate how to use the operating
functions. The examples use matrix A, B and C shown below:

4.1. Adding function VMX.ADD()

In example 4.1.1 we show how to add matrices of the same size. In example 4.1.2 we add two matrices and
a scalar of 3. With the vMx add function, the order of the scalar does not impact the ending result. So if the
scalar of 3 was passed as the first parameter in example 4.1.2 it would not change the result. All matrices
passed as parameters to the adding function must be of the same size.

vMx: Microsoft Excel Linear Algebra Add-in

Page

17

4.2. Subtraction function VMX.SUBTRACT()

In example 4.2.1 we subtract matrix A from B. Example 4.2.2 subtracts a scalar of 7 from matrix B and then
subtract matrix C from the result. With the subtraction function the order of the scalar does impact the
result. In example 4.2.2 we would get an error if we passed the scalar 7 as the first parameter since we
cannot subtract a matrix from a scalar. All matrices passed as parameters to the subtraction function must
be of the same size.
4.3. Multiplying function VMX.MULTIPLY()

In order to multiply two matrices the left matrixs column count must equal the right matrixs row count. In
example 4.3.1 we multiply matrix A times B times D. Example 4.3.2 multiplies matrix C times scalar of 2
times D. When multiplying a matrix by a scalar every matrix element is multiplied by the scalar value. A
scalar can be on the left or right side of a matrix and it will yield the same result. For example scalar of 2
times Matrix A is equivalent to Matrix A times scalar of 2 (i.e. 2 x A = A x 2).

vMx: Microsoft Excel Linear Algebra Add-in

Page

18

4.4. Dividing function VMX.DIVIDE()

In order to divide a matrix by another matrix both need to be of equal dimensions.


For example

]. To divide a matrix by scalar the scalar parameter must be to the right of

the matrix. The function returns an error if you try to divide a matrix by a scalar. Example 4.4.1 divides
matrix A by B and example 4.4.2 divides matrix B by scalar of 2 then matrix C.

vMx: Microsoft Excel Linear Algebra Add-in

Page

19

5. Matrix Decomposition
vMx provides functions to decompose a matrix into a factorization of a product of matrices. With vMx you
can perform a LU, QR, SVD or Cholesky decomposition as discussed below.
5.1. LU Decomposition
vMx includes seven functions that utilizes LU decomposition with partial pivoting where matrix A is factored
into a lower and upper triangular matrices L and U where P * A = L * U. P is the permutation matrix. In this
section we dont demonstrate how to use the function VMX.LU.SOLVE() to solve Ax=b but instead it is
covered in section 7. The vMx functions can only perform a LU decomposition on square matrices. The
seven functions that utilize LU decomposition are listed below.

Name
VMX.LU.COMBO()
VMX.LU.DETERMINANT()
VMX.LU.INVERSE()
VMX.LU.LOWER()
VMX.LU.PERMUTATION()
VMX.LU.SOLVE()
VMX.LU.UPPER()

Parameters
matrix A
matrix A
matrix A
matrix A
matrix A
matrix A, matrix b
matrix A

Description
Returns LU decomposition in one matrix: P * A = L * U
Calculates matrix's determinant using LU decomposition
Inverts matrix using LU decomposition
Returns lower triangular matrix from LU decomposition: P * A = L * U
Returns permutation matrix from LU decomposition: P * A = L * U
Solves Ax=b using LU decomposition
Returns upper triangular matrix from LU decomposition: P * A = L * U

Example 5.1.1

In example 5.1.1 we perform a LU decomposition on matrix A to calculate the permutation, lower and upper
triangular matrices.

vMx: Microsoft Excel Linear Algebra Add-in

Page

20

Examples 5.1.2, 5.1.3 and 5.1.4

Example 5.1.2 returns the lower and upper triangular matrices from a LU decomposition of matrix A from
example 5.1.1 combined in one matrix. In example 5.1.3 we calculate the determinant of matrix A and in
5.1.4 we calculate its inverse.
5.2. QR Decomposition
A QR decomposition of a matrix is a decomposition of a matrix A into a product, where A=QR, of an
orthogonal matrix Q and an upper triangular matrix R. There are two vMx functions that use QR
decomposition. The two are listed below:

Name
Parameters Description
VMX.QR.Q() matrix A
Returns orthogonal matrix Q from QR decomposition
VMX.QR.R() matrix A
Returns upper triangular matrix R from QR decomposition
Example 5.2.1

Example 5.2.1 demonstrates how to find Q and R from a QR decomposition of matrix A.

vMx: Microsoft Excel Linear Algebra Add-in

Page

21

5.3. SVD and Matrix Rank


SVD or Single Value Decomposition is the factorization of matrix A where A = U * SIGMA * Transpose(V). U
is a M-by-M orthogonal matrix, SIGMA is a M-by-N matrix which is zero except for its min (m, n) diagonal
elements and V is a N-by-N orthogonal matrix. There are four vMx functions that utilize SVD decomposition
as listed below:

Name
VMX.SVD.RANK()
VMX.SVD.S()
VMX.SVD.U()
VMX.SVD.VT()

Parameters
matrix A,tolerance
matrix A
matrix A
matrix A

Description
Calculates matrix rank using SVD decomposition
Returns Sigma matrix from SVD decomposition
Returns orthogonal M by M matrix U from SVD decomposition
Returns orthogonal N by N matrix V^t from SVD decomposition

Example 5.3.1

In example 5.3.1 we show how to use the available vMx SVD functions on a matrix A.

vMx: Microsoft Excel Linear Algebra Add-in

Page

22

5.4. Cholesky
Cholesky decomposition is a matrix decomposition of a symmetric positive-definite matrix into the product
of a lower triangular matrix and its conjugate transpose. There are four vMx functions that use Cholesky
decomposition as listed below. We discuss using VMX.CHOLESKY.SOLVE() function in section 7.
Name
VMX.CHOLESKY.IS.SPD()
VMX.CHOLESKY.LOWER()
VMX.CHOLESKY.SOLVE()
VMX.CHOLESKY.UPPER()

Parameters
matrix A
matrix A
matrix A,matrix b
matrix A

Description
Returns true if matrix has cholesky decomposition
Returns lower matrix from cholesky decomposition
Solves Ax=b using cholesky decomposition and returns matrix x
Returns upper matrix from cholesky decomposition

Example 5.4.1

In example 5.4.1 matrices L and U are the upper and lower triangular Cholesky decompositions of matrix A.
We also test if matrix A is Symmetric Definite Positive.

vMx: Microsoft Excel Linear Algebra Add-in

Page

6. Eigen Values and Vectors


In this section we discuss the vMx functions for calculating the Eigen values and vectors of a matrix. All the
Eigen vMx functions only work with square matrices. There are six functions that begin with
VMX.EIGENNONSYM that work with non-symmetric matrices and three functions that begin with
VMX.EIGENSYM that work with symmetric matrices.
Name

Parameters Description
Returns imaginary eigen values in a diagonal matrix for a nonVMX.EIGENNONSYM.IMAGVALMTX() matrix A
symmetric square matrix
Returns imaginary eigen values in a vector for a non-symmetric
VMX.EIGENNONSYM.IMAGVALVCTR() matrix A
square matrix
VMX.EIGENNONSYM.LFTVCTRS()
matrix A
Returns left vectors of a non-symetric square matrix
Returns real eigen values in a diagonal matrix for a non-symmetric
VMX.EIGENNONSYM.REALVALMTX() matrix A
square matrix
Returns real eigen values in a vector for a non-symmetric square
VMX.EIGENNONSYM.REALVALVCTR() matrix A
matrix
VMX.EIGENNONSYM.RGHTVCTRS()
matrix A
Returns right vectors of a non-symetric square matrix
VMX.EIGENSYM.VALMTX()
matrix A
Returns a diagonal matrix with eigen values of a symmetric matrix
VMX.EIGENSYM.VALVTR()
matrix A
Returns eigen values in a diagonal matrix for a symmetric matrix
VMX.EIGENSYM.VECTORS()
matrix A
Returns eigen values in a vector for a symmetric matrix

6.1. Symmetric Examples


Examples 6.1.1 to 6.1.3 demonstrate how to use the symmetric vMx Eigen functions.

vMx: Microsoft Excel Linear Algebra Add-in

23

Page
6.2. Non-Symmetric Examples
Examples 6.2.1 to 6.2.6 demonstrate how to use the non-symmetric vMx Eigen functions.

vMx: Microsoft Excel Linear Algebra Add-in

24

Page

25

7. Solving Ax=b
vMx provides three functions for solving the system of equations Ax=b. To solve matrix x when A is square
matrix we use VMX.LU.SOLVE() which performs a LU decomposition on A. To solve for matrix x when A is
Symmetric Positive Definite (SPD) we can use VMX.CHOLESKY.SOLVE() which performs a Cholesky
decomposition on matrix A. When matrix A is non-square we can use VMX.LEASTSQUARES() to solve for matrix
x which performs a Least square analysis. All three functions can accept matrix b that is bigger than one
column.
Name
VMX.LU.SOLVE()
VMX.CHOLESKY.SOLVE()
VMX.LEASTSQUARES()

Parameters
matrix A, matrix b
matrix A,matrix b
matrix A,matrix b, [error term]

Description
Solves Ax=b using LU decomposition
Solves Ax=b using cholesky decomposition and returns matrix x
Get least squares solution to Ax=b

7.1. Square matrix

In example 7.1.1 we solve for matrix x using a LU decomposition where A is a 4 by 4 matrix and b is a 4 by 1
matrix. In 7.1.2 we solve for matrix x when A is a 3 by 3 matrix and b is a 3 by 2 matrix.
7.2. Symmetric Positive Definite

In example 7.2.1 we solve for matrix x using Cholesky decomposition, where A is a 4 by 4 SPD matrix and b is
a 4 by 1 matrix. In 5.7.2 we solve for matrix x when A is a 3 by 3 SPD matrix and b is a 3 by 2 matrix.

vMx: Microsoft Excel Linear Algebra Add-in

Page

26

7.3. Non-Square

In example 7.3.1 and 7.3.2 we use matrix A which is the daily log returns of the Dow Jones, S&P 500 and
Nasdaq indices over a 14-day period. Matrix b is the daily log returns of Googles stock price over the same
14-day period. In these two example we use VMX.LEASTSQUARES() function to solve for our matrix x. This
function takes three parameters; matrix A, matrix b and a Boolean error term flag. When the error flag is set
to True, the function also returns an error term but none if set to False. In example 7.3.1 we set the error
flag to True but in 7.3.2 it is set to False. If no value is passed as the error flag it defaults to True. When the
columns of matrix A are bigger than its rows, the error flag has no impact.
We can derive the same answer to 7.3.1 using the Excel built in Regression Data Analysis functionality under
the Data Ribbon. However, the resulting answer will be static and will not update automatically if the
underlying data changes. In contrast, the VMX.LEASTSQUARES() function will automatically update when
the data changes. Additionally, Excels built-in regression functionality and the VMX.LEASTSQUARES()
function will produce different results when the columns of matrix A are bigger than its rows.

vMx: Microsoft Excel Linear Algebra Add-in

Page

27

8. Statistical Matrices
In this section we discuss the vMx functions for creating the Co-variance, correlation and standard deviation
matrices for a given data set. All the statistical functions only read and return numbers and do not return name
headers of the data set. Additionally these functions only read points that run along the rows. Excel does have a
built-in data analysis tool for calculating co-variance and correlation matrix. Though unlike the vMx functions, it
is not dynamic and will not update when the underlining data set changes. To demonstrate how to use these
functions we use the same daily log returns data for the Dow Jones index, S&P 500 index, Nasdaq index and
google stock from section 7.3:

8.1. Co-Variance
The following two functions can be used to create the co-variance matrix:
Name
Parameters
Description
VMX.STAT.COVARIANCE() matrix A,column 1,column 2 Calculates covariance of two columns for a given data set
VMX.STAT.COVARMTX()
matrix A
Returns the covariance matrix of given data set

Example 8.1.1 & 8.1.2

In example 8.1.1 we use the VMX.STAT.COVARMTX() function to calculate the co-variance matrix for the
daily log returns. The function returns a 4 by 4 matrix since the data set is four columns. In example 8.1.1
the function is entered as an array formula in cell address B15:E18. In example 8.1.2 we show how we can
calculate the co-variance for two variables. We calculate the co-variance for the S&P and Nasdaq which are
the second and third variable in our data set. The vMx function VMX.STAT.COVARIANCE() produces the
same result as the built-in Excel function COVARIANCE.P() but it is part of the library as a convenience
function. The VMX.STAT.COVARIANCE() function can be used to create the co-variance matrix one element
at a time.

vMx: Microsoft Excel Linear Algebra Add-in

Page

28

8.2. Correlation
The following two functions can be used to create the correlation matrix:
Name
Parameters
Description
VMX.STAT.CORRELATION() matrix A,column 1,column 2 Calculates correlation of two columns for a given data set
VMX.STAT.CORRMTX()
matrix A
Returns the correlation matrix of given data set

Examples 8.2.1 & 8.2.2

In example 8.2.1 we use the VMX.STAT.CORRMTX() function to create the correlation matrix for the daily log
returns. The function returns a 4 by 4 matrix since the data set is four columns. In example 8.1.1 the
function is entered as an array formula in cell address B23:E26. In example 8.2.2 we show how we can
calculate the correlation for two variables. We calculate the correlation for the DJI and S&P which are the
first and second variables in our data set. The vMx function VMX.STAT.CORRELATION() produces the same
result as the built-in Excel function CORREL() but it is part of the library as a convenience function. The
VMX.STAT.CORRELATION() function can be used to create the correlation matrix one element at a time.

vMx: Microsoft Excel Linear Algebra Add-in

Page

29

8.3. Standard deviation


The following two functions can be used to create the standard deviation matrix:
Name
Parameters
Description
VMX.STAT.STANDARDDVTN() matrix A,column 1 Calculates the standard deviation for a given data set column
VMX.STAT.STANDTVNMTX() matrix A
Returns the standard deviation matrix of a given data set

Examples 8.3.1 & 8.3.2

In example 8.3.1 we use the VMX.STAT.STANDTVNMTX() function to create the standard deviation matrix
for the daily log returns. The function returns a 4 by 4 matrix since the data set is four columns. In example
8.1.1 the function is entered as an array formula in cell address B31:E34. In example 8.2.2 we show how
we can calculate the standard deviation for just one index. We calculate the standard deviation for the DJI
which is the first variable in our data set. The vMx function VMX.STAT.STANDARDDVTN() produces the same
result as the built-in Excel function STDEV.P() but it is also part of the library as a convenience function.
The VMX.STAT.STANDARDDVTN() function can be used to create the standard deviation matrix one element
at a time.

vMx: Microsoft Excel Linear Algebra Add-in

Page

30

9. Random and Diagonal Matrices


In this section we cover functions for creating random and diagonal matrices.
9.1. Random integer and real values Matrices
There are two vMx functions for creating matrices of any size where the elements are integer or real values.
There are functions for creating random symmetric matrices with real or integer numbers. The matrixs
dimensions are determined by passing size parameters. The range of the elements is specified by passing a
beginning and ending values range, where the beginning value must be smaller than the ending value. All
four functions have optional parameters for selecting right and left band size. The band size parameters can
only be used when the matrix is square, otherwise the function will return an error. When the band size
parameters are blank then the functions return full-banded matrices. Using the band parameters these
functions can generate diagonal or upper and lower triangular matrices. These functions return random
values each time Excel recalculates the function such as when a new column is inserted.
Name

Parameters
Row size,Column size, Begin value, End value,
VMX.RANDOM.INT
LeftBand, RightBand
Row size,Column size, Begin value, End value,
VMX.RANDOM.REAL
LeftBand, RightBand
Row=Col size, Begin value, End value,Band
VMX.RANDOM.SYMMETRIC.INT size
Row=Col size, Begin value, End value,Band
VMX.RANDOM.SYMMETRIC.REAL size

Description
Returns a matrix with random integer numbers
Returns a matrix with random real numbers
Returns a symmetric matrix with random integer
numbers
Returns a symmetric matrix with random real
numbers

Examples 9.1.1 to 9.1.4

In example 9.1.1 we create a 3 by 4 matrix where the random generated integer values are between 0 and
50 and the banded parameters are left blank so the function returns a full-banded matrix. In example 9.1.2
we create a 3 by 3 symmetric matrix where the real values are between -10 and 20 where both band
parameters are set to zero. Example 9.1.3 demonstrates setting the left and right band parameters to
different values. In example 9.1.4 the function returns a 5 by 5 lower triangular matrix by leaving the left
band parameter blank and setting the right band to zero.

vMx: Microsoft Excel Linear Algebra Add-in

Page

31

Examples 9.1.5 to 9.1.7

Example 9.1.5 demonstrates how to create a 3 by 3 integer symmetric matrix by leaving the band parameter
blank. In example 9.1.6 we create a 3 by 3 diagonal matrix by setting the band parameter to zero.
9.2. Diagonal matrix
There is one function for creating diagonal matrices. The matrixs dimensions are determined by passing
size parameters. You set the value of the diagonal by setting the diagonal value parameter. This function
can be very helpful especially for creating identity matrices.
Name
Parameters
Description
VMX.DIAGONAL() Row size,Column size, Diagonal value Returns a diagonal matrix with passed value on the diagonal

In example 9.2.1 we create a square 3 by 3 diagonal matrix with diagonal value 5.5. In example 9.2.2 we
create a rectangular 3 by 5 matrix with 2 as the diagonal value. We create a 4 by 4 identity matrix in
example 9.2.3. In the last example 9.2.4, we create a 5 by 3 rectangular matrix with 3.00 as the diagonal
value.

vMx: Microsoft Excel Linear Algebra Add-in

Page

32

10. Matrix Utilities


In this section we discuss how to use three vMx utility functions. Using these functions is straightforward as the
examples below will demonstrate.

Name
VMX.IS.SQUARE()
VMX.IS.SYMMETRIC()
VMX.TRANSPOSE()
10.1.

Parameters
matrix A
matrix A
matrix A

Description
Checks wether a matrix is square
Checks wether a matrix is symmetric
Transposes a matrix

Check if square matrix

In example 10.1.1 we check if Matrix A, B and C are square matrices. The square function returns TRUE for A
and B but FALSE for C.
10.2.

Check matrix symmetry

In example 10.2 we check if the same matrices from example 10.1.1 are symmetric.
10.3.

Transpose a matrix

In example 10.3.1 we transpose the three matrices from example 10.1.1

vMx: Microsoft Excel Linear Algebra Add-in

You might also like