previous
this
next
contents
reference
index
search
Using O-Matrix as a Math Analysis Library for VBA
Description
For the VBA developer, O-Matrix can be used as a numerical
analysis library to expand the mathematical analysis
capabilities of VBA.
This example defines a function that uses O-Matrix to calculate
the rank of a matrix and uses this function to calculate
the rank of a matrix defined in a VBA program.
Example
Start O-Matrix. Start Excel and create a new Excel Link
workbook.
In Excel press Alt-F11 to invoke the VBA editor. Right-click
on the Modules folder and select 'Insert | Module'. Paste
the following code into the new module.
Function rank(VBMatrix As Variant) As Integer
Dim status As String
Call OMPutVar("VBMatrix", VBMatrix)
status = OMEval("vbRank = rank(VBMatrix)")
If status <> "OM_OK" Then
MsgBox ("Unable to execute rank command")
Exit Function
End If
rank = OMGetVar("vbRank")
End Function
Sub TestRank()
Dim r(1, 1) As Single
Dim status As String
r(0, 0) = 1#
r(0, 1) = 0#
r(1, 0) = 0#
r(1, 1) = 2#
status = OMOpen()
MsgBox ("Rank of sample matrix = " & Str(rank(r)))
End Sub
Press the F5 key to run the example. Excel will post a dialog displaying the rank of the sample matrix.