This post describes a series of matrix functions compiled from the AlgLib library code (covered in previous posts) as a dll that can be called from Excel VBA, and used as User Defined Functions (UDFs). A spreadsheet containing the necessary VBA code to link to the functions, the compiled dll file, and C++ code for the interface functions can be downloaded from AL-Matrixdll2.zip. The C++ code for the actual matrix functions is all taken from the AlgLib site.
The advantages of these functions over the built in Excel functions, or VBA code are:
- The small limit on maximum matrix size imposed on matrix functions in Excel versions before 2007 is removed.
- The functions operate about 10 times faster than the built in functions and 30 times faster than VBA code (comparisons based on Excel 2007).
- The functions operate on complex numbers as well as real numbers.
- Functions include Eigen Values and Eigen Vectors, solution of systems of linear equations, addition and subtraction, and extraction and insertion, as well as all the functions built into excel.
- The functions are available from VBA without loss of performance.
To install the dll file:
- If you do not have Microsoft Visual Studio C++ installed, either install the program (Express version is a free download), or download and install the redistributable package.
- Copy the dll file to the Windows\System32 folder (or another folder on the system search path)
- The dll functions in Matrixdll2.xls(b) should now work in a similar way to built in functions or VBA UDFs.
Screen shots from the worksheet are shown below: