'*******************************************************
'Visual Basic ActiveX DLL for Matrix calculations
'Version 1.1.1 - 12 Jun 2002
'by C. Somigliana (somic@libero.it)
'
'A DLL with 34 subs and functions for matrix and vector
'calculation. Dimensions are limited only by
'calculation power
'
'HISTORY
'*******************************************************
'This DLL was written for three reasons:
'1. I needed something like this free of charge and I
'   couldn't find it
'2. I think it is not worthy to pay for something based
'   on a public knowledge
'3. I'm amazed to find useful products free of charge
'   in Internet and I want to give my small contribution
'
'I hope you will find this useful
'
'Pls report any bug and/or comment to me, Carlo Somigliana,
'at this e-mail address: somic@libero.it
'Bug fix will be e-mailed free of charge.
'
'Next version depends on if this first release will be
'useful to the Internet community and I receive feedback
'on regards.
'There may be: Error check, fast routines for 3D matrixes,
'rotation and Euler matrixes
'
'regards,
'Carlo
'
'*************************************************************
'
'VERSION HISTORY
'1.00 First release
'1.10 small improvements
'1.1.0 Modified to allow Redim Preserve option for Point array
'     i.e. P(2, n) vs. P(n, 2)
'     Sample code modified consequently
'1.1.1 fixed a bug in mSist
'
'GENERAL INFO
'all numbers are Double
'all indexes are Long
'vet is the vector prefix {vetV}, array with n elements
'mtr is the matrix prefix [mtrA], array with n by m elements
'Vectors are Monodimensional base 1 (es. Dim vetB(1 To 5));
'Matrixes are Bidimensional base 1 (es. Dim mtrA(1 To 2, 1 To 3))
'vetDest is the default Destination vector, storing the result
'mtrDest is the dfault Destination matrix, storing the result
'
'IMPORTANT NOTES:
'-this version has no error check. you have to be sure that
'matrixes have the proper dimensions and characteristics (rows and columns)
'for calculation
'-routines are not optimised for speed, even because VB is not the right
'language for performances. However, some test I did, shew a good calculation
'speed, compared with other routines
'
'LICENSE:
'Freeware for any use. Use this software at you on risk.
'You are free to use and include this software in any program of any kind.
'This sample must be distributed as is, including this readme.txt file.
'The author disclaims any responsibility for any damage may occur using this
'software.
'
'USE: as for any VB ActiveX DLL.
'Include the DLL in your Project (ie. Select Projects > References > VBMatr)
'Declare it in the project (es. Dim m As New Matr)
'
'LIST OF FUNCTIONS (alphabetic order)
'--------------------------------------------------------------------------------
Function mDet(mtrA#()) As Double
'calculate the Determinant of the input matrix mtrA (must be a square matrix)

Sub mDiag(mtrA#())
'Diagonalize mtrA

Sub mDiff(mtrDest#(), mtrSrc1#(), mtrSrc2#())
'subtract two matrixes; put the result in mtrDest
'ie. mtrDest = mtrSrc1 - mtrSrc2

Sub mDivd(ByRef mtrDest#(), mtrSrc1#(), mtrSrc2#())
'divide mtrSrc1 by mtrSrc2; store result in mtrDest

Sub mDupl(mtrDest#(), mtrSrc#())
'duplicate mtrSrc into mtrDest. mtrDest is ReDimensioned to the righ size

Sub mDuplVar(mtrDest#(), VarArray)
'duplicate VarArray (Variant TypeOf Array) into mtrDest. mtrDest is ReDimensioned
'to the righ size (one or two dimension array)
'if VarArray is a number, mtrDest() is 1x1 (i.e. mtrDest(1,1) = VarArray)

Function mGetYPolin(X#, Coeff#()) As Double
'get the Y value associate at the input X value for the Polynomial with the
'coefficients given in the Coeff matrix

Function mIdentical(mtrA#(), mtrB#()) As Boolean
'test if two matrixes are identical

Sub mInv(mtrDest#())
'invert a matrix (i.e. mDet(AI) = 1/mDet(A))

Sub mMakeMatrI(ByRef mtrA#(), ordr As Long)
'create a square unit matrix with ordr rows and colums

Sub mMakeMatrNul(mtrA#(), ordr as Long, ordc As Long)
'create a matrix with ordr rows by ordc cols having all the element zero

Sub mMakeVectI(ByRef vetA#(), ordr As Long)
'create a unit vector with ordr rows

Sub mMakeVectNul(vetA#(), ordr As Long)
'create a vector with ordr rows having all the element zero

Function mMatrAreOrt(mtrA#(), mtrB#()) As Boolean
'test if two matrix are orthogonal

Function mMatrIsOrt(mtrA#()) As Boolean
'test if a matrix is Orthogonal

Function mMatrIsQuadr(mtrDest#()) As Boolean
'Test if a matrix is a square matrix (i.e. rows=cols)

Function mMatrIsSing(mtrA#()) As Boolean
'test if a Matrix Singular (i.e. Determinant = 0). Must be Squared

Function mMatrIsVect(mtrA#()) As Boolean
'Test if a matrix is a vector (i.e. one dimension only)

Function mMatrIsUnit(mtrA#()) As Boolean
'test is a matrix is a Unit matrix (all the elements in the main diagonal are
'1 and all the others are 0)

Function mMatrIsZero(mtrA#()) As Boolean
'test if a matrix is zero (all the elements are zero)

Function mMod(mtrA#()) As Double
'calculate the module of the matrix or vector A
'if A is a matrix, only the first column is used

Sub mMult(mtrDest#(), mtrSrc1#(), mtrSrc2#())
'multiply two matrixes; put the result in mtrDest
'ie. mtrDest = mtrSrc1 * mtrSrc2
'mtrDest is ReDimensioned to the right rows and columns

Sub mMultVett(vetDest#(), mtrSrc#(), vetSrc#())
'multiply one matrix by one vector; put the result in vetDest
'ie. vetDest = mtrSrc * vetSrc
'vetDest is ReDimensioned to the right rows and columns

Sub mOpp(mtrDest#())
'Opposite mtrDest itself (i.e. each mtrDest(r,c) = -mtrDest(r,c))

Sub mPolin(vetCoeff#(), mtrPts#(), Rank&, Optional NoPoints)
'calculate the k coefficients of the polynomial curve interpolating (passing close
'to) the points stored in the mtrPts matrix
'mtrPts must have n rows and 2 columns (column 1 for the x co-ordinate, column 2
'for the y co-ordinate)
'Polynomial is y=Coeff(0) + Coeff(1) * x + Coeff(2) * x^2 + ... + Coeff(k) * x^(k-1)

Sub mPrint(mtrA#(), Optional Perif, Optional Obj, Optional frmt, Optional Comment, Optional Append, Optional Modal)
'print the Matrix or Vector mtrA on a device
'Perif can be 'DEBUG', 'OBJECT', 'MSGBOX', 'CLIPBOARD' or a Filename
'Obj can be Form, PictureBox, Printer, TextBox or Label (if missing DEBUG is used)
'frmt is the format for numbers (if missing Extended Scientific is used: 0.0000E+00)
'Comment is a comment attached in front of the output
'Append Output instead of replacing (True if missing)
'Modal is not used

Sub mProdScal(mtrA#(), Nmr#)
'multiply a matrix by a number

Sub mShowAbout()
'show About form

Sub mSist(vetX#(), mtrA#(), vetB#()):
'solve the matricial system with n equations and n unknowns terms
'{X} = [A]*{B} where
'vetX vector of results, mtrA matrix of coefficients, vetB=known terms
'vectX must be of the right dimension

Sub mSum(mtrDest#(), mtrSrc1#(), mtrSrc2#())
'sum two matrixes; put the result in mtrDest
'ie. mtrDest = mtrSrc1 + mtrSrc2

Sub mSwap(mtrA#(), mtrB#())
'swap two matrixes

Sub mSwapRC(mtrA#(), rc As String, RC1 As Long, RC2 As Long)
'swap row (or column) rc1 with row (or column) rc2 in the matrix
'rc to be 'R' or 'C'

Function mTrace(mtrA#()) As Double
'calculate the Trace of a square matrix (sum of the elements of the main
'diagonal)

Sub mTrasp(mtrDest#(), mtrSrc#())
'Traspose mtrSrc in mtrDest (i.e. swap each r,c with c,r); result in mtrDest,
'properly ReDimensioned, because mtrSrc(m,n) gives mtrDest(n,m)

