Statistica Visual Basic Library of Matrix Functions

Statistica Visual Basic contains a large number of designated matrix and Statistical functions that make the SVB environment ideal for prototyping algorithms or for developing custom Statistical procedures. In order to access the functions of this library, you must either include the file STB.svx at the beginning of the program file (see also Include file STB.svx and the Statistica Visual Basic Library of Matrix Functions) or use the MatrixObject.

One major advantage of using the Statistica library of matrix functions, instead of writing these functions "by hand" in Visual Basic, is that the former will evaluate much faster. For example, when you want to invert large matrices, the MatrixInverse function will perform the actual matrix inversion using the highly optimized (compiled) algorithms of Statistica.

Functions Example and Description
Dim Dim AnArray(10,10) as Variant

'Declares a two-dimensional matrix named AnArray.

Lowess Lowess (arrayX(), arrayY(), .5, 2, 0, Xs, Ys, Rw, Res);

'Computes robust locally weighted regression (LOWESS smoothing) of 2D scatterplot data (x-y pairs).

MatrixAdd Call MATRIXADD(FirstArray(), SecondArray(), ResultArray())

'Adds each element of FirstArray to corresponding element of 'SecondArrayand places result in matrix ResultArray.

MatrixAllNonZero Call MATRIXALLNONZERO(AnArray())

'Assigns 1 to variable ReturnValue if each element of 'AnArray is non-zero, otherwise ReturnValue is set to 0.

MatrixAnyNonZero Call MATRIXANYNONZERO(AnArray())

'Assigns 1 to variable ReturnValue if any element of 'AnArray is non-zero, otherwise ReturnValue is set to 0.

MatrixCholeskyDecomposition Call MATRIXCHOLESKYDECOMPOSITION(FirstArray(), SecondArray())

'Performs Cholesky Decomposition of matrix FirstArray and 'stores results in SecondArray.

MatrixCombineHoriz Call MATRIXCOMBINEHORIZ(FirstArray(), SecondArray(), ResultArray())

'Places values of SecondArray to the right of FirstArray in 'result matrix ResultArray.

MatrixCombineVert Call MATRIXCOMBINEVERT(FirstArray(), SecondArray(), ResultArray())

'Places values of SecondArray below FirstArray in result 'matrix ResultArray.

MatrixCopy Call MATRIXCOPY(FirstArray(), 1, 1, 4, 5, SecondArray(), 1, 2)

'Copies 4 rows, 5 columns from FirstArray beginning at first 'row and first column, and places copied values in SecondArray

'beginning at first row, second column.

MatrixCorrelations Call MATRIXCORRELATIONS(FirstArray(),1,CorrsArray())

'Computes correlations between columns of FirstArray and 'places coefficients in square matrix CorrsArray.

MatrixCrossProductOfDev Call MATRIXCROSSPRODUCTOFDEV(FirstArray(),1,CrossArray())

'Computes squared deviations and crossproducts of deviations 'for matrix FirstArray and places results in square matrix 'CrossArray.

MatrixDet Call MATRIXDET(AnArray(),Det)

'Computes determinant of square matrix AnArray and places 'resulting determinant in variable Det.

MatrixDisplay Call MATRIXDISPLAY(AnArray(),"Spreadsheet Title")

'Displays values of matrix AnArray in a Spreadsheet titled 'Spreadsheet Title.

MatrixDuplicate Call MATRIXDUPLICATE(FirstArray(),Dupl())

'Duplicates matrix FirstArray into matrix Dupl.

MatrixEigenValues Call MATRIXEIGENVALUES(FirstArray(),EigenValues(),EigenValue)

'Places eigenvalues computed for matrix FirstArray into array 'EigenValues and places number of positive eigenvalues computed 'into the variable EigenValue.

MatrixEigenVectors Call MATRIXEIGENVECTORS(FirstArray(), EigenValues(), EigenVectors(),PosEigenValue)

'Places eigenvectors computed for matrix FirstArray into the 'matrix EigenVectors, eigenvalues into vector EigenValues, and 'places number of positive eigenvalues computed into the 'variable PosEigenValue.

MatrixElemAdd Call MATRIXELEMADD(FirstArray(),2,ResultArray())

'Adds constant value (2) to each element of matrix FirstArray 'and places result in matrix ResultArray.

MatrixElemDivide Call MATRIXELEMDIVIDE(FirstArray(),2,ResultArray())

'Divides each element of matrix FirstArray by constant 'value (2) and places result in matrix ResultArray.

MatrixElemMultiply Call MATRIXELEMMULTIPLY(FirstArray(),2,ResultArray())

'Multiplies each element of matrix FirstArray by constant 'value (2) and places result in matrix ResultArray.

MatrixElemSubtract Call MATRIXELEMSUBTRACT(FirstArray(),2,ResultArray())

'Subtracts constant value (2) from each element of matrix 'FirstArray and places result in matrix ResultArray.

MatrixExtract Call MATRIXEXTRACT(FirstArray(),1,2,3,4,SubMatrix())

'Extracts 3 rows, 4 columns of values from matrix FirstArray, 'beginning with row 1, column 2, and places extracted values 'in matrix SubMatrix.

MatrixFill Call MATRIXFILL(2.71828,FirstArray(),2,1,1,0)

'Fills entire second column of matrix FirstArray with the 'value 2.71828.

MatrixGeneralPseudoInverse Call MATRIXGENERALPSEUDOINVERSE(FirstArray(),ResultArray())

'Computes the generalized inverse of the matrix FirstArray 'and places it in the matrix ResultArray.

MatrixGetColumn Call MATRIXGETCOLUMN(FirstArray(),3,ResultArray())

'Extracts the third column from the matrix FirstArray and 'places it in the matrix ResultArray.

MatrixGetDiagonal Call MATRIXGETDIAGONAL(FirstArray(),ResultArray())

'Extracts the main diagonal from the matrix FirstArray and 'places it in the matrix ResultArray.

MatrixGetRow Call MATRIXGETROW(FirstArray(),2,ResultArray())

'Extracts the second row from the matrix FirstArray and 'places it in the matrix ResultArray.

MatrixGramSchmidtOrt Call MATRIXGRAMSCHMIDTORT(FirstArray(),ResultArray())

'Performs Gram-Schmidt orthonormalization of the matrix 'FirstArray and places results in the matrix ResultArray.

MatrixIdentity Call MATRIXIDENTITY(AnArray())

'Sets the values of matrix AnArray to the identity matrix '(1 along main diagonal, 0 elsewhere).

MatrixInverse Call MATRIXINVERSE(FirstArray(),ResultArray())

'Computes the inverse of the matrix FirstArray and places 'it in the matrix ResultArray.

MatrixIsEqual Call MATRIXISEQUAL(FirstArray(), SecondArray(), ResultArray())

'Compares each element of FirstArray to the corresponding 'element of SecondArray and if equal, places a 1 in the 'corresponding element of matrix ResultArray.

MatrixIsGreater Call MATRIXISGREATER(FirstArray(), SecondArray(), ResultArray())

'Compares each element of FirstArray to the corresponding 'element of SecondArray and if value of FirstArray is greater, 'places a 1 in the corresponding element of matrix ResultArray.

MatrixIsGreaterEqual Call MATRIXISGREATEREQUAL(FirstArray(), SecondArray(), ResultArray())

'Compares each element of FirstArray to the corresponding 'element of SecondArray and if value of FirstArray is equal 'or greater, places a 1 in the corresponding element of matrix 'ResultArray.

MatrixIsLess Call MATRIXISLESS(FirstArray(), SecondArray(), ResultArray())

'Compares each element of FirstArray to the corresponding 'element of SecondArray and if value of FirstArray is less, 'places a 1 in the corresponding element of matrix ResultArray.

MatrixIsLessEqual Call MATRIXISLESSEQUAL(FirstArray(), SecondArray(), ResultArray())

'Compares each element of FirstArray to the corresponding 'element of SecondArray and if value of FirstArray is equal or 'less, places a 1 in the corresponding element of matrix 'ResultArray.

MatrixIsNotEqual Call MATRIXISNOTEQUAL(FirstArray(), SecondArray(), ResultArray())

'Compares each element of FirstArray to the corresponding 'element of SecondArray and if not equal, places a 1 in the 'corresponding element of matrix ResultArray.

MatrixKroneckerMultiply Call MATRIXKRONECKERMULTIPLY(FirstArray(), SecondArray(), ResultArray())

'Computes the Kronecker product of the matrices FirstArray 'and SecondArray and places results in the matrix ResultArray.

MatrixLogicalAnd Call MATRIXLOGICALAND(FirstArray(), SecondArray(), ResultArray())

'Performs a logical comparison of each element of FirstArray 'with the corresponding element of SecondArray and if both are

'true (values > 0), places a 1 in the corresponding element of 'matrix ResultArray.

MatrixLogicalNot Call MATRIXLOGICALNOT(FirstArray(),ResultArray())

'Performs a logical negation of each element of FirstArray '(where true = values > 0), places result in the 'corresponding element of matrix ResultArray.

MatrixLogicalOr Call MATRIXLOGICALOR(FirstArray(), SecondArray(), ResultArray())

'Performs a logical comparison of each element of FirstArray 'with the corresponding element of SecondArray and if either 'is true (values > 0), places a 1 in the corresponding element 'of matrix ResultArray.

MatrixMeans Call MATRIXMEANS(FirstArray(), ResultArray())

'Computes means of columns of FirstArray and places results 'in ResultArray.

MatrixMultiply Call MATRIXMULTIPLY(FirstArray(), SecondArray(), ResultArray())

'Multiplies the matrices FirstArray by SecondArray and places 'results in ResultArray.

MatrixRank Call MATRIXRANK(AnArray(),Result)

'Computes the rank of matrix AnArray and places result in 'variable Result.

MatrixRead Call MATRIXREAD("C:\Matrix.txt", AnArray())

'Reads the contents of text file "C:\Matrix.txt" into 'matrix AnArray.

MatrixReadFromDataFile Call MATRIXREADFROMDATAFILE("C:\Data.sta",1,1,0,0,AnArray())

'Reads the contents of data file "C:\Data.sta" into matrix 'AnArray.

MatrixSetColumn Call MATRIXSETCOLUMN(ResultsArray(),2, AnArray())

'Places the contents of the second column of matrix 'AnArray into the second column of matrix ResultsArray.

MatrixSetDiagonal Call MATRIXSETDIAGONAL(ResultArray(), AnArray())

'Places the contents of the main diagonal of matrix 'AnArray into the main diagonal of matrix ResultsArray.

MatrixSetRow Call MATRIXSETROW(ResultArray(),3, AnArray())

'Places the contents of the third row of matrix AnArray 'into the third row of matrix ResultArray.

MatrixSetToZero Call MATRIXSETTOZERO(AnArray())

'Sets all values of matrix AnArray to zero.

MatrixSingularValues Call MATRIXSINGULARVALUES(AnArray(), ResultArray())

'Computes singular values of matrix AnArray and places them 'into matrix ResultArray.

MatrixSingularValuesDecomp Call MATRIXSINGULARVALUESDECOMP(FirstArray(), ResultArray1(), ResultArray2(),ResultArray3())

'Performs singular value decomposition of matrix FirstArray and 'places resultant values into matrix ResultArray1, matrix 'ResultArray2, and matrix ResultArray3.

MatrixSolve Call MATRIXSOLVE(FirstArray(), ArrayB(), ArrayX())

'For each column vector in ArrayX and ArrayB, solves the linear 'equations FirstArray * vectorX = vectorB and places the 'results in the respective columns of ArrayX.

MatrixSubtract Call MATRIXSUBTRACT(FirstArray(), SecondArray(), ResultArray())

'Subtracts each element of SecondArray from corresponding 'element of FirstArray and places result in matrix ResultArray.

MatrixSumOfSquares Call MATRIXSUMOFSQUARES(AnArray(), Result)

'Computes sum of squares of each element of AnArray and 'places result in variable Result.

MatrixSweep Call MATRIXSWEEP(AnArray(),1,10,-1)

'Performs backward sweep of AnArray from column 1 to 10.

MatrixTrace Call MATRIXTRACE(AnArray(), Result)

'Computes trace of matrix AnArray and places result in 'variable Result.

MatrixTranspose Call MATRIXTRANSPOSE(AnArray(), Result)

'Transposes matrix AnArray and places result in matrix Result.

MatrixWrite Call MATRIXWRITE("C:\Matrix.txt",AnArray())

'Writes the contents of matrix AnArray into text file "C:\Matrix.txt".

NewScrollsheet NewScrollsheet(2, 3, AnArray, 'New Spreadsheet', 'Row 1|Row 2', 'Col A|Col B|Col C')

'Creates a new 2 row by 3 column Spreadsheet from the 'contents of matrix AnArray and names the rows and columns.

ReDim Dim AnArray()

ReDim AnArray(10)

'Dynamically changes the size of AnArray.

ScrollsheetGetMatrix ScrollsheetGetMatrix(scroll1, 1, 2, AnArray)

'Extracts values from the specified Spreadsheet beginning 'at row 1, column 2 and assigns the values to the 'matrix AnArray.

ScrollsheetSetMatrix ScrollsheetSetMatrix(scroll1, 2, 4, AnArray)

'Places the contents of the matrix AnArray into 'the specified Spreadsheet beginning at row 2, column 4.

VectorDualSort Call VECTORDUALSORT(Vector, IndexVector, SORT_ASCENDING)

'Sorts the elements of Vector into ascending order; 'the elements of IndexVector are rearranged, so that 'the pairs of values Vector(i) and IndexVector(i) 'remain the same.

VectorRank Call VECTORRANK(Vector, SORT_ASCENDING, RANK_MEAN)

'Ranks the elements of Vector in ascending order, 'assigning mean ranks to tied values.

VectorSort Call VECTORSORT(Vector, SORT_DESCENDING)

'Sorts the elements of Vector in descending order.