Class Matrix
This abstract FB is the basis for all other matrix FBs. It represents a 2D array of LREAL elements.
It provides dozens of methods and properties useful for manipulating itself, calculating values, and comparing to other matricies.
Critically, this base class does not actually contain any mechanism for storing the values of the matrix (that is the responsibility of the specific inheriting sub-class).
Because Matrix is an abstract FB it cannot be assigned (:=) directly.
Instead, each Matrix is always passed in and out of a function AS REFERENCE.
This also allows interactions with inhereted sub-classes of Matrix more easily.
info
Namespace: PlcDocu.TcMatrix
Assembly: TcMatrixConnector.dll
Syntax
public abstract class Matrix
Properties
| Improve this Doc View SourceAverage
Returns the average value of all elements
Declaration
[IgnoreReflection]
public dynamic Average { get; }
Property Value
| Type | Description |
|---|---|
| System.Object | Plc type LREAL; Twin type: Vortex.Connector.ValueTypes.OnlinerLReal |
Cols
Returns the number of columns in the matrix
Declaration
[IgnoreReflection]
public dynamic Cols { get; }
Property Value
| Type | Description |
|---|---|
| System.Object | Plc type UINT; Twin type: Vortex.Connector.ValueTypes.OnlinerUInt |
IsEmpty
Returns true if the matrix does not have any addresible elements
Declaration
[IgnoreReflection]
public dynamic IsEmpty { get; }
Property Value
| Type | Description |
|---|---|
| System.Object | Plc type Bool; Twin type: |
IsSquare
Returns true if this matrix is not empty, and the number of columns is equal to the number of rows
Declaration
[IgnoreReflection]
public dynamic IsSquare { get; }
Property Value
| Type | Description |
|---|---|
| System.Object | Plc type BOOL; Twin type: Vortex.Connector.ValueTypes.OnlinerBool |
IsVector
Returns true if this matrix is not empty, and at least one dimension has a size of 1 (row vector or column vector).
Declaration
[IgnoreReflection]
public dynamic IsVector { get; }
Property Value
| Type | Description |
|---|---|
| System.Object | Plc type BOOL; Twin type: Vortex.Connector.ValueTypes.OnlinerBool |
Length
Total number of elements in this matrix
Declaration
[IgnoreReflection]
public dynamic Length { get; }
Property Value
| Type | Description |
|---|---|
| System.Object | Plc type UINT; Twin type: Vortex.Connector.ValueTypes.OnlinerUInt |
MaxVal
Returns the maximum value from all elements
Declaration
[IgnoreReflection]
public dynamic MaxVal { get; }
Property Value
| Type | Description |
|---|---|
| System.Object | Plc type LREAL; Twin type: Vortex.Connector.ValueTypes.OnlinerLReal |
MinVal
Returns the minimum value from all elements
Declaration
[IgnoreReflection]
public dynamic MinVal { get; }
Property Value
| Type | Description |
|---|---|
| System.Object | Plc type LREAL; Twin type: Vortex.Connector.ValueTypes.OnlinerLReal |
Rows
Total number of rows in this matrix
Declaration
[IgnoreReflection]
public dynamic Rows { get; }
Property Value
| Type | Description |
|---|---|
| System.Object | Plc type UINT; Twin type: Vortex.Connector.ValueTypes.OnlinerUInt |
Sum
Returns the sum of all elements
Declaration
[IgnoreReflection]
public dynamic Sum { get; }
Property Value
| Type | Description |
|---|---|
| System.Object | Plc type LREAL; Twin type: Vortex.Connector.ValueTypes.OnlinerLReal |
Methods
| Improve this Doc View SourceClear()
Resets the value of every element in this matrix to zero Sets the value of every element to 0.0
Declaration
[IgnoreReflection]
public void Clear()
CopyFrom(Object)
Copy the value from each element in the source matrix to each corresponding element in this matrix Prerequisites:
- This matrix is the same size as the source matrix
- Neither matrix is empty
Declaration
[IgnoreReflection]
public dynamic CopyFrom(dynamic M)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Object | M | Source of the copy operation |
Returns
| Type | Description |
|---|---|
| System.Object | Returns true if the prerequisites were met and the data was copied, false otherwise |
ElementDifference(Object)
For each element in this matrix, calculate a new value by Subtracting the value of the corresponding element of the supplied matrix from the value in this matrix THIS := THIS - M :Prerequisites:
- This matrix is the same size as the supplied matrix
- Neither matrix is empty
Declaration
[IgnoreReflection]
public dynamic ElementDifference(dynamic M)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Object | M | The subtrahend in the subtraction |
Returns
| Type | Description |
|---|---|
| System.Object | TRUE if the operation completes successfully, false if the prerequisites are not met |
ElementProduct(Object)
For each element in this matrix, calculate a new value by Multiplying the value of the corresponding element of the supplied matrix with the value in this matrix THIS := THIS .* M :Prerequisites:
- This matrix is the same size as the supplied matrix
- Neither matrix is empty
Declaration
[IgnoreReflection]
public dynamic ElementProduct(dynamic M)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Object | M | the supplied matrix to be multiplied element-by-element to this matrix |
Returns
| Type | Description |
|---|---|
| System.Object | TRUE if the operation completes successfully, false if the prerequisites are not met |
ElementSum(Object)
For each element in this matrix, calculate a new value by Adding the value of the corresponding element of the supplied matrix with the value in this matrix THIS := THIS + M Prerequisites:
- This matrix is the same size as the supplied matrix
- Neither matrix is empty
Declaration
[IgnoreReflection]
public dynamic ElementSum(dynamic M)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Object | M | The supplied matrix to be added to this matrix |
Returns
| Type | Description |
|---|---|
| System.Object | TRUE if the operation completes successfully, false if the prerequisites are not met |
FillFrom(Object)
For every element that exist in both this matrix and the source matrix, copy the value from the source matrix into this matrix
Declaration
[IgnoreReflection]
public void FillFrom(dynamic M)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Object | M | source matrix for element copy operation |
FillTrapezoidal(Object, Object, Object)
Fills all elements of this matrix based on which of three zones it is located into when considered as a trapezoidal matrix
Declaration
[IgnoreReflection]
public void FillTrapezoidal(dynamic Diagonal, dynamic UpperRight, dynamic LowerLeft)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Object | Diagonal | Every element on the main diagonal of the matrix is set to this value. |
| System.Object | UpperRight | Every element above or to the right of the main diagonal is set to this value |
| System.Object | LowerLeft | Every element below or to the left of the main diagonal is set to this value |
GetI(Object)
Gets the value of the element in this matrix at the supplied location as if the elements were stored in a 1D row-major array Prerequisites:
- I < Rows*Cols
- Matrix is not empty
note
If the supplied index is out of bounds the value 0 is returned and a warning is generated in the Error List
Declaration
[IgnoreReflection]
public dynamic GetI(dynamic I)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Object | I | The index of the element which should have its value returned |
Returns
| Type | Description |
|---|---|
| System.Object | The value of the element at the specified index, or 0 if an invalid index is supplied |
GetRC(Object, Object)
Returns the value of the element of this matrix at the specified row and column. Prerequisites:
- Row < Rows
- Col < Cols
- Matrix is not empty
important
If the supplied or or column is out of bounds then a warning message is generated in the Error List and the value 0 is returned
important
The value of the element at the specified row and column, or 0 if an invalid index is supplied
Declaration
[IgnoreReflection]
public dynamic GetRC(dynamic Row, dynamic Col)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Object | Row | The row of the element to fetch |
| System.Object | Col | The column of the element to fetch |
Returns
| Type | Description |
|---|---|
| System.Object | Returns the value of the element at the specified (0-indexed) position within the matrix |
GetSize(Object)
Returns the length of the matrix in the specified dimension
If an invalid dimension is supplied then a warning is generated in the Error List and the value 0 is returned
The length of the matrix in the specified dimension, or 0 if the dimension specified is invalid
important
important
Declaration
[IgnoreReflection]
public dynamic GetSize(dynamic Dim)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Object | Dim | The dimension of the matrix for which the size should be returned. 0=Rows, 1=Cols |
Returns
| Type | Description |
|---|---|
| System.Object | Plc type UINT; Twin type: Vortex.Connector.ValueTypes.OnlinerUInt |
GetVectorMagnitude()
Calcualtes the vector magnitude of this matrix (square root of the sum of the squares), assuming it is a vector. :Prerequisites:
- This matrix is not empty and is a vector
important
If this matrix is empty or is not a vector, 0 is returned
Declaration
[IgnoreReflection]
public dynamic GetVectorMagnitude()
Returns
| Type | Description |
|---|---|
| System.Object | The vector magnitude of this matrix if it is a vector, otherwise 0 |
InvertSquare(Object)
Inverts the matrix. May fail if the matrix is too close to being singular. Use the tolerance input to specify how close to go (1E-6 to 1E-9 is porbably good). :Prerequisites:
- This matrix is square
- This matrix is not empty
Declaration
[IgnoreReflection]
public dynamic InvertSquare(dynamic Tolerance)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Object | Tolerance | The smallest magnitude of number that is allowed to be used as a denominator in the calculation of the inverse |
Returns
| Type | Description |
|---|---|
| System.Object | True if the inverse has been calculated. False if a precondition was not met, or a near-singularity was detected (data may be malformed). |
IsEqualSize(Object)
Returns TRUE if IsEqualSize is true AND every element in this matrix is equal to its corresponding element in the supplied matrix
Checks if this matrix is the same size (number of rows and number of columns match) as the supplied matrix.
two empty matricies are considered the same size.
note
Declaration
[IgnoreReflection]
public dynamic IsEqualSize(dynamic M)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Object | M | The matrix which should have its size compared to the size of this matrix |
Returns
| Type | Description |
|---|---|
| System.Object | True if this matrix is the same size as the supplied matrix |
IsNearlyEqual(Object, Object)
Determines if this matrix is nearly equal to a supplied matrix, based on a supplied precision.
Two matricies are considered nearly equal if they are the same size and every set of corresponding elements are equal to within the supplied precision.
Note that two empty matricies are considered equal
note
Declaration
[IgnoreReflection]
public dynamic IsNearlyEqual(dynamic M, dynamic Precision)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Object | M | The other matrix to compare to this one |
| System.Object | Precision | Deviation between two elements larger than this value makes them unequal |
Returns
| Type | Description |
|---|---|
| System.Object | TRUE if the two matricies are nearly equal, FALSE if they are not |
Power(Object)
Raises every element of the matrix to the supplied power
Many values of exponent could easily cause all of the elements to turn into NaN!
important
Declaration
[IgnoreReflection]
public void Power(dynamic Exponent)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Object | Exponent | Power with which to raise every element of the matrix |
Scale(Object)
Scales every element of this matrix by the supplied value
Declaration
[IgnoreReflection]
public void Scale(dynamic Scalar)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Object | Scalar | Value with which to scale every element of this matrix |
SetI(Object, Object)
Sets the element specified BY the supplied index TO the suppleid value, assuming the data OF the matrix is stored in a 1D row-major ARRAY Prerequisites: - I < Rows*Cols
Declaration
[IgnoreReflection]
public dynamic SetI(dynamic I, dynamic Val)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Object | I | The index specifying which element should be modified |
| System.Object | Val | The value copied to the corresponding element |
Returns
| Type | Description |
|---|---|
| System.Object | TRUE if the specified index is valid and the data is copied. FLASE otherwise |
SetRC(Object, Object, Object)
Sets the element specified by the supplied row and column to the suppleid value Prerequisites:
- Row < Rows
- Col < Cols
- Matrix is not empty
important
If the supplied or or column is out of bounds then a warning message is generated in the Error List and the value 0 is returned The value of the element at the specified row and column, or 0 if an invalid index is supplied
Declaration
[IgnoreReflection]
public dynamic SetRC(dynamic Row, dynamic Col, dynamic Val)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Object | Row | The row of the element to set |
| System.Object | Col | The column of the element to set |
| System.Object | Val | The value to copy into the specified element |
Returns
| Type | Description |
|---|---|
| System.Object | TRUE if the specified row and column are valid and the data is copied. FALSE otherwise |
SortByColAsc(Object)
Sorts the matrix by swapping entire rows around until the specified column is in ascending order. The relative position of equal rows will remain unchanged so as to allow tiered sorting. In-place bubble sort of rows by the specified col, into ascending order algorithm is 'stable', meaning that two equivalent rows will maintain their relative position after This is nice because it lets you sort by secondary/tertiary/etc columns (if you do them in reverse)
Declaration
[IgnoreReflection]
public dynamic SortByColAsc(dynamic SortCol)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Object | SortCol | Plc type : UINT [VAR_INPUT]; Twin type : Vortex.Connector.ValueTypes.OnlinerUInt
|
Returns
| Type | Description |
|---|---|
| System.Object | Returns the value of the element at the specified (0-indexed) position within the matrix |
TransposeSquare()
Transposes the matrix.
:Prerequisites:
- This matrix is square
- This matrix is not empty
Declaration
[IgnoreReflection]
public dynamic TransposeSquare()
Returns
| Type | Description |
|---|---|
| System.Object | TRUE if the operation completes successfully, false if the prerequisites are not met |