MathMatrix IEC Library for ACSELERATOR RTAC Projects

Similar documents
IEC Library for ACSELERATOR RTAC Projects

x = 12 x = 12 1x = 16

IPAliasRedundancy. IEC Library for ACSELERATOR RTAC Projects. SEL Automation Controllers

SELRand IEC Library for ACSELERATOR RTAC Projects

Exercise Set Decide whether each matrix below is an elementary matrix. (a) (b) (c) (d) Answer:

Quicksort IEC Library for ACSELERATOR RTAC Projects

Basic Matrix Manipulation with a TI-89/TI-92/Voyage 200

FreeMat Tutorial. 3x + 4y 2z = 5 2x 5y + z = 8 x x + 3y = -1 xx

Matrices. A Matrix (This one has 2 Rows and 3 Columns) To add two matrices: add the numbers in the matching positions:

Vector: A series of scalars contained in a column or row. Dimensions: How many rows and columns a vector or matrix has.

SCIE 4101, Spring Math Review Packet #4 Algebra II (Part 1) Notes

TUTORIAL 1 Introduction to Matrix Calculation using MATLAB TUTORIAL 1 INTRODUCTION TO MATRIX CALCULATION USING MATLAB

Chapter 4 Section 2 Operations on Decimals

SELRand. IEC Library for ACSELERATOR RTAC Projects. SEL Automation Controllers

0_PreCNotes17 18.notebook May 16, Chapter 12

Binary Addition. Add the binary numbers and and show the equivalent decimal addition.

Maths for Signals and Systems Linear Algebra in Engineering. Some problems by Gilbert Strang

Solving Systems Using Row Operations 1 Name

Computers in Engineering. Linear Algebra Michael A. Hawker

Computers in Engineering COMP 208. Representing Vectors. Vector Operations 11/29/2007. Scaling. Adding and Subtracting

Digital Fundamentals. CHAPTER 2 Number Systems, Operations, and Codes

Identity Matrix: >> eye(3) ans = Matrix of Ones: >> ones(2,3) ans =

MAT 275 Laboratory 2 Matrix Computations and Programming in MATLAB

M4.1-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE

Homework #3 CS2255 Fall 2012

DynamicDisturbanceRecorder

Pre-Calculus. Slide 1 / 192. Slide 2 / 192. Slide 3 / 192. Matrices

Pre-Calculus Matrices

Pre-Calculus. Introduction to Matrices. Slide 1 / 192 Slide 2 / 192. Slide 3 / 192. Slide 4 / 192. Slide 6 / 192. Slide 5 / 192. Matrices

Introduction to MATLAB

1 Overview of the standard Matlab syntax

The MatriCs. Reloaded. A linear algebra-specific language for the budding C enthusiast. Short name: MaC Extension:.neo

Finite Math - J-term Homework. Section Inverse of a Square Matrix

Introduction to MATLAB

Application Note. Creating PLCopen Compliant Function Blocks in IEC 61131

Computer Packet 1 Row Operations + Freemat

PieNum Language Reference Manual

Introduction to MatLab. Introduction to MatLab K. Craig 1

Heap Management. Heap Allocation

PowerPoints organized by Dr. Michael R. Gustafson II, Duke University

Matrix Multiplication

MATH 2000 Gauss-Jordan Elimination and the TI-83 [Underlined bold terms are defined in the glossary]

carry in carry 1101 carry carry

Matrix Multiplication

CMAT Language - Language Reference Manual COMS 4115

MAT 275 Laboratory 2 Matrix Computations and Programming in MATLAB

Arithmetic and Logic Blocks

Chapter 1: Number and Operations

Matrix Inverse 2 ( 2) 1 = 2 1 2

OLIVETTI PROGRAMMA 101 QUICK GUIDE adapted by L.C. Sep from Computer Structures: Readings and Examples C.G. Bell, McGraw Hill 1971

MATH 423 Linear Algebra II Lecture 17: Reduced row echelon form (continued). Determinant of a matrix.

3-8 Solving Systems of Equations Using Inverse Matrices. Determine whether each pair of matrices are inverses of each other. 13.

Chapter 10 - Computer Arithmetic

10/26/ Solving Systems of Linear Equations Using Matrices. Objectives. Matrices

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #16 Loops: Matrix Using Nested for Loop

Introduction to MATLAB Programming

Report on the Language A

Preface... 1 The Boost C++ Libraries Overview... 5 Math Toolkit: Special Functions Math Toolkit: Orthogonal Functions... 29

Matrices 4: use of MATLAB

MAT 275 Laboratory 2 Matrix Computations and Programming in MATLAB

Curriculum Map: Mathematics

SCHOOL OF ENGINEERING & BUILT ENVIRONMENT. Mathematics. Numbers & Number Systems

GridLang: Grid Based Game Development Language Language Reference Manual. Programming Language and Translators - Spring 2017 Prof.

What We Will Learn Today

AH Matrices.notebook November 28, 2016

The inverse of a matrix

C+X. Complex Arithmetic Toolkit. Introduction

University of Alberta

Basic Data Acquisition with LabVIEW

To start using Matlab, you only need be concerned with the command window for now.

Essentials for the TI-83+

New Jersey Center for Teaching and Learning. Progressive Mathematics Initiative

Chapter 18 out of 37 from Discrete Mathematics for Neophytes: Number Theory, Probability, Algorithms, and Other Stuff by J. M. Cargal.

Teaching Manual Math 2131

Geometric transformations assign a point to a point, so it is a point valued function of points. Geometric transformation may destroy the equation

Arrays, Matrices and Determinants

COMPUTER ARITHMETIC (Part 1)

Interactive Math Glossary Terms and Definitions

Add a multiple of a row to another row, replacing the row which was not multiplied.

B. V. Patel Institute of Business Management, Computer & Information Technology, UTU 2013

Physics 326G Winter Class 2. In this class you will learn how to define and work with arrays or vectors.

COSC2430: Programming and Data Structures Sparse Matrix Addition 2 2: Non-recursive and recursive; arrays and linked lists

Computational Methods CMSC/AMSC/MAPL 460. Vectors, Matrices, Linear Systems, LU Decomposition, Ramani Duraiswami, Dept. of Computer Science

CS184: Using Quaternions to Represent Rotation

Introduction and MATLAB Basics

CS129: Introduction to Matlab (Code)

Eng Marine Production Management. Introduction to Matlab

Chapter 8 Virtual Memory

MATLAB for Experimental Research. Fall 2018 Vectors, Matrices, Matrix Operations

Introduction to programming in MATLAB

SML: Specialized Matrix Language White Paper

Review of the C Programming Language

CS314 Exam 1 - Spring Suggested Solution and Criteria 1

Chapter 4. Matrix and Vector Operations

Getting To Know Matlab

Introduction to Matlab

Solving General Linear Equations w/ Excel

Twister: Language Reference Manual

MATLAB Lesson I. Chiara Lelli. October 2, Politecnico di Milano

Computational Methods CMSC/AMSC/MAPL 460. Vectors, Matrices, Linear Systems, LU Decomposition, Ramani Duraiswami, Dept. of Computer Science

Transcription:

MathMatrix IEC 61131 Library for ACSELERATOR RTAC Projects SEL Automation Controllers

Contents 1 Introduction 5 1.1 Special Considerations................................. 5 2 Supported Firmware Versions 7 3 Enumerations 8 3.1 enum_matrixstate................................... 8 4 Functions 9 4.1 fun_deletematrix (Function)............................. 9 4.2 fun_matrixadd (Function).............................. 9 4.3 fun_matrixcopycolumn (Function)......................... 10 4.4 fun_matrixdeterminant (Function)......................... 11 4.5 fun_matrixgaussianelim (Function)......................... 12 4.6 fun_matrixinvert (Function)............................. 13 4.7 fun_matrixmultiply (Function)............................ 14 4.8 fun_matrixsubtract (Function)............................ 15 4.9 fun_matrixtranspose (Function)........................... 15 4.10 fun_matrix_ata (Function)............................. 16 4.11 fun_newmatrix (Function).............................. 17 5 Classes 18 5.1 class_matrix (Class).................................. 18 5.1.1 Clear (Method)................................. 18 5.1.2 MatrixRowAdd (Method)........................... 18 5.1.3 MatrixRowDivide (Method).......................... 19 5.1.4 MatrixRowMultiply (Method)......................... 20 5.1.5 MatrixRowSubtract (Method)......................... 20 5.1.6 MatrixScale (Method)............................. 21 5.1.7 MatrixStepRowAdd (Method)......................... 21 5.1.8 MatrixStepRowDivide (Method)....................... 22 5.1.9 MatrixStepRowMultiply (Method)...................... 23 5.1.10 MatrixStepRowSubtract (Method)...................... 23 5.1.11 MatrixStepScale (Method).......................... 24 5.1.12 MatrixTimedRowAdd (Method)....................... 25 5.1.13 MatrixTimedRowDivide (Method)...................... 26 5.1.14 MatrixTimedRowMultiply (Method)..................... 26 5.1.15 MatrixTimedRowSubtract (Method)..................... 27 5.1.16 MatrixTimedScale (Method)......................... 28 5.1.17 RowSwap (Method).............................. 28 5.1.18 SetSize (Method)................................ 29 5.1.19 StartMatrixOperation (Method)....................... 30 5.2 class_matrixadd (Class)............................... 30 5.2.1 LockMatrices (Method)............................ 31 5.2.2 ProcessSteps (Method)............................ 31 5.2.3 ProcessTimed (Method)............................ 32 5.2.4 UnlockMatrices (Method)........................... 33 2015 Schweitzer Engineering Laboratories, Inc. 2

5.3 class_matrixcopycolumn (Class).......................... 33 5.3.1 LockMatrices (Method)............................ 33 5.3.2 ProcessSteps (Method)............................ 34 5.3.3 ProcessTimed (Method)............................ 34 5.3.4 UnlockMatrices (Method)........................... 35 5.4 class_matrixdeterminant (Class)........................... 35 5.4.1 LockMatrices (Method)............................ 36 5.4.2 ProcessSteps (Method)............................ 36 5.4.3 ProcessTimed (Method)............................ 37 5.4.4 UnlockMatrices (Method)........................... 38 5.5 class_matrixgaussianelim (Class).......................... 38 5.5.1 LockMatrices (Method)............................ 39 5.5.2 ProcessSteps (Method)............................ 39 5.5.3 ProcessTimed (Method)............................ 40 5.5.4 UnlockMatrices (Method)........................... 41 5.6 class_matrixinvert (Class).............................. 42 5.6.1 LockMatrices (Method)............................ 42 5.6.2 ProcessSteps (Method)............................ 43 5.6.3 ProcessTimed (Method)............................ 43 5.6.4 UnlockMatrices (Method)........................... 44 5.7 class_matrixmultiply (Class)............................. 45 5.7.1 LockMatrices (Method)............................ 45 5.7.2 ProcessSteps (Method)............................ 46 5.7.3 ProcessTimed (Method)............................ 46 5.7.4 UnlockMatrices (Method)........................... 47 5.8 class_matrixsubtract (Class)............................. 47 5.8.1 LockMatrices (Method)............................ 47 5.8.2 ProcessSteps (Method)............................ 48 5.8.3 ProcessTimed (Method)............................ 49 5.8.4 UnlockMatrices (Method)........................... 50 5.9 class_matrixtranspose (Class)............................ 50 5.9.1 LockMatrices (Method)............................ 50 5.9.2 ProcessSteps (Method)............................ 51 5.9.3 ProcessTimed (Method)............................ 51 5.9.4 UnlockMatrices (Method)........................... 52 5.10 class_matrix_ata (Class).............................. 52 5.10.1 LockMatrices (Method)............................ 53 5.10.2 ProcessSteps (Method)............................ 54 5.10.3 ProcessTimed (Method)............................ 54 5.10.4 UnlockMatrices (Method)........................... 55 Appendices 56 Appendix A Release Notes 57 Appendix B Benchmarks 58 B.1 Benchmark Platforms................................. 58 B.2 Benchmark Test s............................. 58 B.2.1 fun_deletematrix............................... 58 2015 Schweitzer Engineering Laboratories, Inc. 3

B.2.2 fun_matrixadd................................ 58 B.2.3 fun_matrixcopycolumn........................... 58 B.2.4 fun_matrixdeterminant............................ 58 B.2.5 fun_matrixgaussianelim........................... 59 B.2.6 fun_matrixinvert............................... 59 B.2.7 fun_matrixmultiply.............................. 59 B.2.8 fun_matrixsubtract.............................. 59 B.2.9 fun_matrixtranspose............................. 59 B.2.10 fun_matrixtranspose (Hermitian)...................... 59 B.2.11 fun_matrix_ata............................... 59 B.2.12 fun_matrix_ata (Hermitian)........................ 59 B.2.13 fun_newmatrix................................ 59 B.3 Benchmark Results................................... 60 Appendix C Examples 61 C.1 Solving a System of Equations............................ 61 C.1.1 Objective.................................... 61 C.1.2 Assumptions.................................. 61 C.1.3 Solution..................................... 61 C.2 Manipulating a Matrix Across Multiple Scans.................... 63 C.2.1 Objective.................................... 63 C.2.2 Assumptions.................................. 63 C.2.3 Solution..................................... 63 C.3 Troubleshooting a Matrix............................... 66 C.3.1 Objective.................................... 66 C.3.2 Assumptions.................................. 66 C.3.3 Solution..................................... 66 2015 Schweitzer Engineering Laboratories, Inc. 4

1 Introduction The MathMatrix library allows the creation of matrices of complex numbers. There are multiple desired workflows that exist when working with matrices and the library provides several options for working with them. The library is designed to facilitate two basic types of matrix operations: operations that modify an existing matrix and operations that take one or more matrices as arguments and place the result in a different matrix. Operations that affect only the active matrix are completed using the methods on class_matrix objects. Operations that affect two or more matrices are performed by external functions or special matrix manipulation classes. The library also allows for operations of varying levels of required immediacy. For work on large or highly variant sized matrices that can be completed over multiple task cycles, it provides matrix manipulation classes that are loaded with operator and result matrices, stimulated to run to completion, and given a fixed number of steps or a fixed time slice 1. For operations that must complete immediately, ideally on fixed sized matrices so the computation time can be evaluated to validate timing requirements, functions provided by the library accomplish the same work while guaranteeing the completion of the algorithm before returning. This library is dependent on the capabilities defined in the MathComplex Library 2 for all operations. 1.1 Special Considerations Copying classes from this library will cause undesired behavior. This means the following: 1. The assignment operator := must not be used on any class from this library; consider assigning pointers to the objects instead. // This is bad and in most cases will provide a compiler error like: // "C0328: Assignment not allowed for type class_mathmatrixobject" mymathmatrixobject := othermathmatrixobject; // This is fine somevariable := mymathmatrixobject.value; // As is this pt_mymathmatrixobject := ADR(myMathMatrixObject); 2. Classes from this library must never be VAR_INPUT or VAR_OUTPUT members in Function Blocks, Functions, or Methods; place them in the VAR_IN_OUT section or use pointers instead. Classes in this library have memory allocated inside them. As such, they should only be created in environments of permanent scope (e.g., Programs, Global Variable Lists, or VAR_STAT sections). 1 Because of the cost of checking the system time, the time is not validated at each step in the algorithm but rather after multiple steps have been completed. 2 See the MathComplex documentation for more information on the operation of this library. 2015 Schweitzer Engineering Laboratories, Inc. 5

Though this library provides the capability to dynamically resize, create, and destroy matrices, memory operations can be long running and care should be taken to avoid unnecessary use of this type of operation on a time-critical task. 2015 Schweitzer Engineering Laboratories, Inc. 6

2 Supported Firmware Versions This library can be used on any device that is configured using acselerator RTAC SEL-5033 Software with firmware version R132 or higher. 2015 Schweitzer Engineering Laboratories, Inc. 7

3 Enumerations Enumerations make code more readable by allowing a specific number to have a readable textual equivalent. 3.1 enum_matrixstate Enumeration NOT_INITIALIZED NO_OPERATION MATRIX_SCALE EXTERNAL_OPERATION MATRIX_ROW_STEP_MULT MATRIX_ROW_STEP_DIV MATRIX_ROW_STEP_ADD MATRIX_ROW_STEP_SUB This matrix has no memory assigned to it, call SetSize() to initialize. The matrix is not locked to any operation. The matrix is being scaled by one value. The matrix is being operated on by an external class. The matrix is multiplying a row by a scalar. The matrix is dividing a row by a scalar. The matrix is adding two rows together. The matrix is subtracting one row from another. 2015 Schweitzer Engineering Laboratories, Inc. 8

4 Functions 4.1 fun_deletematrix (Function) The user should call this after completing work on a matrix received through fun_newmatrix() before the matrix goes out of scope. It releases all system resources. pt_matrix POINTER TO class_matrix The matrix to be deleted. This pointer must be received through fun_newmatrix. True if the memory is successfully deallocated. This function frees all system resources owned by this matrix. After completion of the function pt_matrix is NULL(0). 4.2 fun_matrixadd (Function) This function adds two matrices and places the result in a third. complete before the function returns. The entire operation will matrix1 class_matrix The first addend. matrix2 class_matrix The second addend. result class_matrix The sum of the two matrices. The matrix addition completed successfully. This function sets the return value to true if all conditions for performing the addition are met: 2015 Schweitzer Engineering Laboratories, Inc. 9

1. matrix1 and matrix2 are initialized. 2. All three matrices are not busy performing a stepwise operation. 3. result is a separate matrix from both matrix1 and matrix2. 4. matrix1 and matrix2 have the same dimensions. 5. If necessary, result is successfully resized. It then performs the addition. 4.3 fun_matrixcopycolumn (Function) This function copies one column from one matrix to a column in a second matrix. The entire operation will complete before the function returns. Inputs fromcolumn UINT The column index of the column being copied from. tocolumn UINT The column index of the column being copied to. frommatrix class_matrix The matrix being copied from. tomatrix class_matrix The matrix being copied to. The column copy completed successfully. This function sets the return value to true if all conditions for performing the copy are met: 1. Both matrices are initialized. 2. Both matrices are not busy performing a stepwise operation. 3. Both matrices have the same number of rows. 4. The column indices provided are within the size of the matrices referenced. It then performs the copy. 2015 Schweitzer Engineering Laboratories, Inc. 10

4.4 fun_matrixdeterminant (Function) This function calculates the determinant of a square matrix. The entire operation will complete before the function returns. If the purpose behind calculating the determinant is a check before inverting a matrix or as part of the process of solving a system of equations this class is not the most optimal to use. In these cases it is better to use the fun_matrixinvert or the fun_matrixgaussianelim object instead as the overhead for all three is similar. original class_matrix The matrix to calculate the determinant of. This matrix is left unchanged. workspace class_matrix Memory to do the calculation in. If this is the same size as original, no memory allocation will occur in finding the determinant. Outputs determinant struct_complexrect The determinant of the matrix. Zero if the matrix is not invertible. s true if the operation was attempted. This function sets the return value to true if all conditions for performing the calculation are met: 1. original is initialized. 2. original is a square matrix. 3. workspace is a separate matrix from original. 4. Neither matrix is busy performing some other operation. 5. If necessary, workspace is successfully resized. Copies the contents of original into workspace. Reduces workspace to an identity matrix using elementary row operations. Calculates the determinant from the row operations performed. 2015 Schweitzer Engineering Laboratories, Inc. 11

If at any time the row operations cannot reduce workspace further and it is still not an identity matrix, the operation is terminated and determinant is set to zero. 4.5 fun_matrixgaussianelim (Function) This function simplifies a matrix to a diagonal ones matrix with trailing columns using Gaussian elimination. The contents of coefficients are destroyed and the contents of solutions are modified by this function. The entire operation will complete before the function returns. coefficients class_matrix The coefficients of the variables being solved for. solutions class_matrix The right hand side of the system of equations. Outputs error This algorithm cannot solve this system of equations. s true if the Gaussian elimination was attempted and the matrices could have been modified. This function sets the return value to true if all conditions for performing the calculation are met: 1. Both matrices are initialized. 2. Both matrices are not busy performing a stepwise operation. 3. coefficients is a separate matrix from solutions. 4. coefficients has at least as many columns as rows. 5. solutions has the same number of rows as coefficients. Reduces the first Rows Rows of coefficients to an identity matrix using elementary row operations. Performs the same row operations on solutions. If at any time the row operations cannot reduce coefficients further and there is still not an identity matrix on the left the operation is terminated and error is set. The contents of coefficients are destroyed and the contents of solutions are modified by this method. 2015 Schweitzer Engineering Laboratories, Inc. 12

Output Combination Meanings error return FALSE FALSE This should never occur. FALSE TRUE The Gaussian elimination completed successfully. TRUE FALSE The matrix state prevented the Gaussian elimination request. TRUE TRUE The matrix is not invertible and cannot be reduced by this Gaussian elimination algorithm. 4.6 fun_matrixinvert (Function) This function creates the inverse of a square matrix. original is destroyed in the process so if the data are still desired, they must be copied before the function is called. The entire operation will complete before the function returns. One common use case for inverting a matrix is to solve a system of equations. In this library that use case is discouraged unless solving the same system for many solutions as Gaussian elimination performs the same functionality with less overhead. original class_matrix The matrix to invert. result class_matrix The inverted matrix. Outputs error The inversion could not be attempted or original cannot be inverted. s true if inversion was attempted and the matrices could have been modified. This function sets the return value to true if all conditions for performing the calculation are met: 1. original is initialized. 2. Both matrices are not busy performing a stepwise operation. 3. result is a separate matrix from original. 2015 Schweitzer Engineering Laboratories, Inc. 13

4. original is a square matrix. 5. If necessary, result is successfully resized. Sets result to an identity matrix. Reduces original to an identity matrix using elementary row operations. Performs the same row operations on result to create the inverse. If at any time the row operations cannot reduce original further and it is still not an identity matrix, the operation is terminated and error is set. Output Combination Meanings error return FALSE FALSE This should never occur. FALSE TRUE The inversion completed successfully. TRUE FALSE The matrix state prevented the inversion request. TRUE TRUE The matrix is not invertible. 4.7 fun_matrixmultiply (Function) This function multiplies two matrices and places the result in a third. The entire operation will complete before the function returns. matrix1 class_matrix The multiplier. matrix2 class_matrix The multiplicand. result class_matrix The product of the two matrices. The matrix multiplication completed successfully. This function sets the return value to true if all conditions for performing the calculation are met: 1. matrix1 and matrix2 are initialized. 2. All three matrices are not busy performing a stepwise operation. 3. result is a separate matrix from both matrix1 and matrix2. 2015 Schweitzer Engineering Laboratories, Inc. 14

4. The column count of matrix1 equals the row count of matrix2. If necessary, it sets the size of result. It then performs the multiplication. 4.8 fun_matrixsubtract (Function) This function subtracts one matrix from another and places the result in a third. The entire operation will complete before the function returns. matrix1 class_matrix The minuend. matrix2 class_matrix The subtrahend. result class_matrix The difference of the two matrices. The matrix subtraction completed successfully. This function verifies that the subtraction can be performed: 1. matrix1 and matrix2 are initialized. 2. All three matrices are not busy performing a stepwise operation. 3. result is a separate matrix from both matrix1 and matrix2. 4. matrix1 and matrix2 have the same dimensions. If necessary, the function resizes result. It then performs the subtraction. 4.9 fun_matrixtranspose (Function) This function places the transpose of a matrix into a result. The entire operation will complete before the function returns. Inputs conjugate The result of this operation will be the Hermitian Transpose. Before each element is placed in result, it will be conjugated. 2015 Schweitzer Engineering Laboratories, Inc. 15

original class_matrix The matrix whose transpose is calculated. result class_matrix The transpose of the original matrix. The matrix transpose completed successfully. This function verifies that the transpose can be performed: 1. original is initialized. 2. Both matrices are not busy performing a stepwise operation. 3. result is a separate matrix from original. If necessary the function resizes result. It then performs the transpose. If conjugate is true, conjugate each element in result. 4.10 fun_matrix_ata (Function) This function performs an optimization of the operation (A T A) transposing an input matrix and multiplying it by itself. The entire operation will complete before the function returns. Inputs conjugate The result of this operation will be calculated using the Hermitian Transpose. Before the transpose step is complete, each element will be conjugated. original class_matrix The matrix A. result class_matrix The matrix for the result. s true if the operation completed successfully. 2015 Schweitzer Engineering Laboratories, Inc. 16

This function verifies that the operation can be performed: 1. original is initialized. 2. Both matrices are not busy performing a stepwise operation. 3. result is a separate matrix from original. If necessary, the function resizes result. It then performs the operation A T A. If conjugate is true, conjugate each element in the transpose before using it in the multiply. 4.11 fun_newmatrix (Function) Request a new matrix from the system with all required resources. Matrices received through this function must be freed through the fun_deletematrix() function before they leave scope. Inputs rows UINT The number of rows in the new matrix. cols UINT The number of columns in the new matrix. POINTER TO class_matrix The address of the new class_matrix. This function allocates system resources for a rows by cols matrix of struct_complexrect objects. 2015 Schweitzer Engineering Laboratories, Inc. 17

5 Classes This library provides the following classes as extensions of the IEC 61131 function block. 5.1 class_matrix (Class) This is the fundamental class for this library. It allows for the storage of struct_complexrect objects ordered by row and column. It manages all required system resources internally. Initialization Inputs The following inputs are required when the class is instantiated. rowcount UINT The number of rows this matrix begins with. colcount UINT The number of columns this matrix begins with. Outputs pt_data POINTER TO POINTER TO Pointer to an array of pointers (one for each struct_complexrect row). Allows accessing the matrix with [row][col] syntax. Indexing starts at zero. This pointer should be re-read before access after any resize operation. Rows UINT The number of rows in the matrix. Cols UINT The number of columns in the matrix. State enum_matrixstate The active matrix operation. 5.1.1 Clear (Method) This method returns all system resources internal to this matrix and sets its size to zero rows by zero columns. In addition it clears all locks on the matrix and resets all internal state machines. This should typically be used only to free the system resources held by this matrix before it goes out of scope. 5.1.2 MatrixRowAdd (Method) This method adds one row to another inside this matrix, replacing the content of the second row (M atrix[torow] = M atrix[torow] + M atrix[f romrow] scalar). The entire operation will complete before the method returns. 2015 Schweitzer Engineering Laboratories, Inc. 18

Inputs fromrow UINT The first addend. torow UINT The second addend and the location of the result. scalar struct_complexrect A constant that is multiplied against the value of each entry in fromrow before adding it to the entry in torow. s true if the method performed the addition. Validates that the matrix is initialized and not in the middle of a stepwise operation. Validates that the provided row indices exist. If the checks pass, multiplies fromrow by scalar and adds the result to torow. fromrow remains unchanged. 5.1.3 MatrixRowDivide (Method) This method divides each element in rowindex by scalar and stores the results back in rowindex (M atrix[rowindex] = M atrix[rowindex]/scalar). The entire operation will complete before the method returns. Inputs rowindex UINT The row to be modified. scalar struct_complexrect A constant used as the divisor against the value of each entry in rowindex. s true if the method performed the division. Validates that the matrix is initialized and not in the middle of a stepwise operation. Validates the row index provided exists. If the checks pass, divides each entry in rowindex by scalar. 2015 Schweitzer Engineering Laboratories, Inc. 19

5.1.4 MatrixRowMultiply (Method) This method multiplies each element in rowindex by scalar and stores the results back in rowindex (M atrix[rowindex] = M atrix[rowindex] scalar). The entire operation will complete before the method returns. Inputs rowindex UINT The row to be modified. scalar struct_complexrect A constant used as the multiplier against the value of each entry in rowindex. s true if the method performed the multiplication. Validates that the matrix is initialized and not in the middle of a stepwise operation. Validates the row index provided exists. If the checks pass, multiplies each entry in rowindex by scalar. 5.1.5 MatrixRowSubtract (Method) This method subtracts one row from another inside this matrix, replacing the content of the second row (M atrix[torow] = M atrix[torow] M atrix[f romrow] scalar). The entire operation will complete before the method returns. Inputs fromrow UINT The subtrahend. torow UINT The minuend and the location of the result. scalar struct_complexrect A constant that is multiplied against the value of each entry in fromrow before subtracting it from the entry in torow. s true if the method performed the subtraction. 2015 Schweitzer Engineering Laboratories, Inc. 20

Validates that the matrix is initialized and not in the middle of a stepwise operation. Validates the row indices provided exist. If the checks pass, multiplies fromrow by scalar and subtracts the result from torow. fromrow remains unchanged. 5.1.6 MatrixScale (Method) Multiplies each element in this matrix by a scalar. The entire operation will complete before the method returns. Inputs scalar struct_complexrect A constant that is multiplied against the value of each entry this matrix. s true if the method scaled the matrix. Validates that the matrix is initialized and not in the middle of a stepwise operation. If the checks pass, multiplies each element in the matrix by scalar, placing the result in the same location. 5.1.7 MatrixStepRowAdd (Method) This method adds one row to another inside this matrix, replacing the content of the second row (M atrix[torow] = M atrix[torow] + M atrix[f romrow] scalar). The operation will perform the next steps operations of the complete addition. This design allows for the completion of the algorithm over the course of multiple task cycles for matrices large enough for completion time to be a concern. steps UDINT The number of operations to attempt this task cycle. 2015 Schweitzer Engineering Laboratories, Inc. 21

s true if the method completed the addition. Validates that the matrix is initialized and has begun a stepwise addition. If the checks pass, this method uses the values provided in StartMatrixOperation() to multiply fromrow by scalar and add the result to torow. fromrow remains unchanged. Performs, at most, the next steps operations toward completing the addition algorithm. Decrements steps by the number of operations consumed. s true and unlocks the matrix if the addition completed. s false if the addition was not attempted or steps was exhausted before the algorithm completed. 5.1.8 MatrixStepRowDivide (Method) This method divides each element in torow by scalar and stores the results back in torow (M atrix[torow] = M atrix[torow]/scalar). The operation will perform the next steps operations of the complete division. This design allows for the completion of the algorithm over the course of multiple task cycles for matrices large enough for completion time to be a concern. steps UDINT The number of operations to attempt this task cycle. s true if the method completed the division. Validates that the matrix is initialized and has begun a stepwise division. If the checks pass, this method uses the values provided in StartMatrixOperation() to divide each element in torow by scalar. Performs, at most, the next steps operations toward completing the division algorithm. Decrements steps by the number of operations consumed. 2015 Schweitzer Engineering Laboratories, Inc. 22

s true and unlocks the matrix if the division completed. s false if the division was not attempted or steps was exhausted before the algorithm completed. 5.1.9 MatrixStepRowMultiply (Method) This method multiplies each element in torow by scalar and stores the results back in torow (M atrix[torow] = M atrix[torow] scalar). The operation will perform the next steps operations of the complete multiplication. This design allows for the completion of the algorithm over the course of multiple task cycles for matrices large enough for completion time to be a concern. steps UDINT The number of operations to attempt this task cycle. s true if the method completed the multiplication. Validates that the matrix is initialized and has begun a stepwise multiplication. If the checks pass, this method uses the values provided in StartMatrixOperation() to multiply each entry in torow by scalar. Performs, at most, the next steps operations toward completing the multiplication algorithm. Decrements steps by the number of operations consumed. s true and unlocks the matrix if the multiplication completed. s false if the multiplication was not attempted or steps was exhausted before the algorithm completed. 5.1.10 MatrixStepRowSubtract (Method) This method subtracts one row from another inside this matrix, replacing the content of the second row (M atrix[torow] = M atrix[torow] M atrix[f romrow] scalar). The operation will perform the next steps operations of the complete subtraction. This design allows for the completion of the algorithm over the course of multiple task cycles for matrices large enough for completion time to be a concern. 2015 Schweitzer Engineering Laboratories, Inc. 23

steps UDINT The number of operations to attempt this task cycle. s true if the method completed the subtraction. Validates that the matrix is initialized and has begun a stepwise subtraction. If the checks pass, this method uses the values provided in StartMatrixOperation() to multiply fromrow by scalar and subtract the result from torow. fromrow remains unchanged. Performs, at most, the next steps operations toward completing the subtraction algorithm. Decrements steps by the number of operations consumed. s true and unlocks the matrix if the subtraction completed. s false if the subtraction was not attempted or steps was exhausted before the algorithm completed. 5.1.11 MatrixStepScale (Method) Multiplies each element in this matrix by a scalar. The operation will perform the next steps operations of the complete scaling operation. This design allows for the completion of the algorithm over the course of multiple task cycles for matrices large enough for completion time to be a concern. steps UDINT The number of operations to attempt this task cycle. s true if the method completed the scaling operation. Validates that the matrix is initialized and has begun a stepwise scaling operation. 2015 Schweitzer Engineering Laboratories, Inc. 24

If the checks pass, this method uses the values provided in StartMatrixOperation() to multiply each element in the matrix by scalar. Performs, at most, the next steps operations toward completing the scaling algorithm. Decrements steps by the number of operations consumed. s true and unlocks the matrix if the scaling operation completed. s false if the scaling operation was not attempted or steps was exhausted before the algorithm completed. 5.1.12 MatrixTimedRowAdd (Method) This method adds one row to another inside this matrix, replacing the content of the second row (M atrix[torow] = M atrix[torow] + M atrix[f romrow] scalar). The operation will perform work for the next duration microseconds toward completion of the addition. This design allows for the completion of the algorithm over the course of multiple task cycles for matrices large enough for completion time to be a concern. duration UDINT The number of microseconds to spend on this calculation. s true if the method completed the addition. Validates that the matrix is initialized and has begun a stepwise addition. If the checks pass, this method uses the values provided in StartMatrixOperation() to multiply fromrow by scalar and add the result to torow. fromrow remains unchanged. Performs work toward completing the addition algorithm, in groups of steps, until duration microseconds is exceeded. Decrements duration by the microseconds consumed. s true and unlocks the matrix if the addition completed. s false if the addition was not attempted or duration was exhausted before the algorithm completed. 2015 Schweitzer Engineering Laboratories, Inc. 25

5.1.13 MatrixTimedRowDivide (Method) This method divides each element in torow by scalar and stores the results back in torow (M atrix[torow] = M atrix[torow]/scalar). The operation will perform work for the next duration microseconds toward the complete division. This design allows for the completion of the algorithm over the course of multiple task cycles for matrices large enough for completion time to be a concern. duration UDINT The number of microseconds to spend on this calculation. s true if the method completed the division. Validates that the matrix is initialized and has begun a stepwise division. If the checks pass, this method uses the values provided in StartMatrixOperation() to divide each element in torow by scalar. Performs work toward completing the division algorithm, in groups of steps, until duration microseconds is exceeded. Decrements duration by the microseconds consumed. s true and unlocks the matrix if the division completed. s false if the division was not attempted or duration was exhausted before the algorithm completed. 5.1.14 MatrixTimedRowMultiply (Method) This method multiplies each element in torow by scalar and stores the results back in torow (M atrix[torow] = M atrix[torow] scalar). The operation will perform work for the next duration microseconds toward the complete multiplication. This design allows for the completion of the algorithm over the course of multiple task cycles for matrices large enough for completion time to be a concern. duration UDINT The number of microseconds to spend on this calculation. 2015 Schweitzer Engineering Laboratories, Inc. 26

s true if the method completed the multiplication. Validates that the matrix is initialized and has begun a stepwise multiplication. If the checks pass, this method uses the values provided in StartMatrixOperation() to multiply each entry in torow by scalar. Performs work toward completing the multiplication algorithm, in groups of steps, until duration microseconds is exceeded. Decrements duration by the microseconds consumed. s true and unlocks the matrix if the multiplication completed. s false if the multiplication was not attempted or duration was exhausted before the algorithm completed. 5.1.15 MatrixTimedRowSubtract (Method) This method subtracts one row from another inside this matrix, replacing the content of the second row (M atrix[torow] = M atrix[torow] M atrix[f romrow] scalar). The operation will perform work for the next duration microseconds toward the complete subtraction. This design allows for the completion of the algorithm over the course of multiple task cycles for matrices large enough for completion time to be a concern. duration UDINT The number of microseconds to spend on this calculation. s true if the method completed the subtraction. Validates that the matrix is initialized and has begun a stepwise subtraction. If the checks pass, this method uses the values provided in StartMatrixOperation() to multiply fromrow by scalar and subtract the result from torow. fromrow remains unchanged. Performs work toward completing the subtraction algorithm, in groups of steps, until duration microseconds is exceeded. 2015 Schweitzer Engineering Laboratories, Inc. 27

Decrements duration by the microseconds consumed. s true and unlocks the matrix if the subtraction completed. s false if the subtraction was not attempted or duration was exhausted before the algorithm completed. 5.1.16 MatrixTimedScale (Method) Multiplies each element in this matrix by a scalar. The operation will perform work for the next duration microseconds toward the complete scaling operation. This design allows for the completion of the algorithm over the course of multiple task cycles for matrices large enough for completion duration to be a concern. duration UDINT The number of microseconds to spend on this calculation. s true if the method completed the scaling operation. Validates that the matrix is initialized and has begun a stepwise scaling operation. If the checks pass, this method uses the values provided in StartMatrixOperation() to multiply each element in the matrix by scalar. Performs work toward completing the scaling algorithm, in groups of steps, until duration microseconds is exceeded. Decrements duration by the microseconds consumed. s true and unlocks the matrix if the scaling operation completed. s false if the scaling operation was not attempted or duration was exhausted before the algorithm completed. 5.1.17 RowSwap (Method) This method exchanges the position of two rows in a given matrix. Inputs row1 UINT The first row to swap. row2 UINT The second row to swap. 2015 Schweitzer Engineering Laboratories, Inc. 28

s true if the method performed the row swap. Validates that the matrix is initialized and not performing any stepwise operation. If the checks pass, swaps the positions of row1 and row2. s true if the swap succeeded. s false if the swap failed. 5.1.18 SetSize (Method) This method changes the storage capacity of the matrix modifying Rows and Cols. Inputs rowcount UINT The new number of rows. colcount UINT The new number of columns. s true if the method resized the matrix. Validates that the matrix is not performing any stepwise operation. If either rowcount or colcount is zero, sets Rows and Cols to zero and frees all system resources. If both rowcount equals Rows and colcount equals Cols, leaves the matrix unchanged. If rowcount is greater than Rows, adds zeroed rows to the bottom of the matrix. If rowcount is less than Rows, removes rows from the bottom of the matrix. If colcount is greater than Cols, adds zeros to the end of each row. If colcount is less than Cols, truncates each row to the new count. s true if the matrix is the newly requested size. s false if the matrix is not the newly requested size. If the resize fails, the matrix retains all old values. 2015 Schweitzer Engineering Laboratories, Inc. 29

5.1.19 StartMatrixOperation (Method) This method must be called to configure any stepwise or timed operation on only this matrix. It accepts and stores the values used during the operation. Inputs operation enum_matrixstate The stepwise operation to begin. fromrow UINT The row to use in the modification. Used only in addition and subtraction. torow UINT The row to be modified. scalar struct_complexrect The constant value to be used during the operation. s true if the method locked the matrix to the requested operation. Validates that the matrix is initialized and not performing any stepwise operation. Validates row indices required for the operation requested. For addition and subtraction, both indices must be within the matrix. For multiplication and division, only torow is validated. For scaling operations, no row index is validated Stores scalar for use during the operation. Locks the matrix to prevent other operations from occurring. s true if the operation is primed. s false if anything prevents the operation from being primed. 5.2 class_matrixadd (Class) This class handles the locking handshakes and the state required to add two class_matrix objects over the course of multiple scans. Outputs Busy This class has locked class_matrix instances and is in the middle of a calculation. 2015 Schweitzer Engineering Laboratories, Inc. 30

5.2.1 LockMatrices (Method) This method primes the class to perform a new addition (result = matrix1 + matrix2). It must be called before each addition of two matrices to be performed. matrix1 class_matrix The first addend. matrix2 class_matrix The second addend. result class_matrix The sum of matrix1 and matrix2. s true if the addition operation is now ready. s false if either matrix1 or matrix2 is not initialized. s false if result is not a separate matrix from both matrix1 and matrix2. s false if any of the three matrices is busy doing any stepwise operation. s false if the dimensions of matrix1 do not match those of matrix2. s false if result cannot be made to be the same dimensions as the other two matrices. s false if it cannot lock all matrices involved in the operation. If all other checks succeeded, then stores required references, sets Busy to true, and returns true. The contents of result are destroyed by this method. 5.2.2 ProcessSteps (Method) This method performs the addition algorithm on three already locked-in matrices. The operation will perform the next steps sub-operations of the complete addition algorithm. steps UDINT The number of sub-operations to attempt this task cycle. s true if the addition completed. 2015 Schweitzer Engineering Laboratories, Inc. 31

Validates that LockMatrices() has been successfully called. Adds each element in matrix1 to its corresponding element in matrix2 and stores the sum in result. Decrements steps by the number of operations performed. s true if the addition algorithm completed before steps was exhausted. s false if LockMatrices() has not been called or steps was exhausted before completing the algorithm. 5.2.3 ProcessTimed (Method) This method performs the addition algorithm on three already locked-in matrices. The operation will perform work for the next duration microseconds toward the complete addition algorithm. duration UDINT The number of microseconds to spend on this calculation. s true if the addition completed. Validates that LockMatrices() has been successfully called. Adds each element in matrix1 to its corresponding element in matrix2 and stores the sum in result. Performs work toward completing the addition algorithm, in groups of steps, until duration microseconds is exceeded. Decrements duration by the microseconds consumed. s true if the addition algorithm completed before duration was exhausted. s false if LockMatrices() has not been called or duration was exhausted before completing the algorithm. 2015 Schweitzer Engineering Laboratories, Inc. 32

5.2.4 UnlockMatrices (Method) This method unlocks any matrices locked by LockMatrices(). It only needs to be called by the user if the matrix operation has been terminated early by calling Clear() on any of the dependent matrices. In all other cases, the matrices will be unlocked on completion of the algorithm. Requests that all locked matrices free themselves for other operations. Sets Busy to false. 5.3 class_matrixcopycolumn (Class) This class handles the locking handshakes and the state required to copy a column from one class_matrix object to another over the course of multiple scans. Outputs Busy This class has locked class_matrix instances and is in the middle of a calculation. 5.3.1 LockMatrices (Method) This method primes the class to perform a new column copy. column copy to be performed. It must be called before each Inputs fromcolumn UINT The index of the column to copy from. tocolumn UINT The index of the column to copy to. frommatrix class_matrix The matrix to be copied from. tomatrix class_matrix The matrix to be copied to. s true if the copy operation is now ready. 2015 Schweitzer Engineering Laboratories, Inc. 33

s false if either frommatrix or tomatrix is not initialized. s false if either of the matrices is busy doing any stepwise operation. s false if Rows of matrix1 does not match Rows of matrix2. s false if either index provided is outside of the corresponding matrix. s false if it cannot lock all matrices involved in the operation. If all other checks succeeded, then stores required references, sets Busy to true, and returns true. 5.3.2 ProcessSteps (Method) This method performs the copy algorithm on two already locked-in matrices. The operation will perform the next steps sub-operations of the complete copy. steps UDINT The number of sub-operations to attempt this task cycle. s true if the copy completed. Validates that LockMatrices() has been successfully called. Copies each element in column fromcolumn of frommatrix to its corresponding element in column tocolumn of tomatrix. Decrements steps by the number of sub-operations performed. s true if the copy algorithm completed before steps was exhausted. s false if LockMatrices() has not been called or steps was exhausted before completing the algorithm. 5.3.3 ProcessTimed (Method) This method performs the copy algorithm on two already locked-in matrices. The operation will perform work for the next duration microseconds toward the complete copy. 2015 Schweitzer Engineering Laboratories, Inc. 34

duration UDINT The number of microseconds to spend on this calculation. s true if the copy completed. Validates that LockMatrices() has been successfully called. Copies each element in column fromcolumn of frommatrix to its corresponding element in column tocolumn of tomatrix. Performs work toward completing the copy algorithm, in groups of steps, until duration microseconds is exceeded. Decrements duration by the microseconds consumed. s true if the copy algorithm completed before duration was exhausted. s false if LockMatrices() has not been called or duration was exhausted before completing the algorithm. 5.3.4 UnlockMatrices (Method) This method unlocks any matrices locked by LockMatrices(). It only needs to be called by the user if the matrix operation has been terminated early by calling Clear() on any of the dependent matrices. In all other cases, the matrices will be unlocked on completion of the algorithm. Requests that all locked matrices free themselves for other operations. Sets Busy to false. 5.4 class_matrixdeterminant (Class) This class handles the locking handshakes and the state required to calculate the determinant of a matrix over the course of multiple scans. If the purpose behind calculating the determinant is a check before inverting a matrix or as part of the process of solving a system of equations this class is not the most optimal to use. In these cases it is better to use the class_matrixinvert or the class_matrixgaussianelim object instead as the overhead for all three is similar. 2015 Schweitzer Engineering Laboratories, Inc. 35

Outputs Busy This class has locked class_matrix instances and is in the middle of a calculation. 5.4.1 LockMatrices (Method) This method primes the class to calculate the determinant of a new matrix. It must be called before each operation to be performed. original class_matrix The matrix to calculate the determinant of. This matrix is left unchanged. workspace class_matrix Memory to do the calculation in. If this is the same size as original, no memory allocation will occur in finding the determinant. s true if the operation is now ready. s false if original is not initialized. s false if workspace is not a separate matrix from original. s false if either of the matrices is busy doing any stepwise operation. s false if original is not a square matrix. s false if workspace cannot be resized to the correct dimensions. s false if it cannot lock all matrices involved in the operation. If all other checks succeeded, then stores required references, sets Busy to true, and returns true. The contents of workspace are destroyed by this method. 5.4.2 ProcessSteps (Method) This method computes the determinant of an already locked-in matrix. The operation will perform the next steps sub-operations of the complete task. 2015 Schweitzer Engineering Laboratories, Inc. 36

steps UDINT The number of sub-operations to attempt this task cycle. Outputs determinant struct_complexrect The determinant of the matrix. Zero if the calculation is incomplete or the matrix is not invertible. s true if the operation completed. Validates that LockMatrices() has been successfully called. Decrements steps by the number of sub-operations performed. s true and outputs the calculated determinant if the algorithm completed before steps was exhausted. s false and outputs a determinant of zero if LockMatrices() has not been called or steps was exhausted before completing the algorithm. In the case that the matrix is not invertible, outputs a determinant of zero. 5.4.3 ProcessTimed (Method) This method computes the determinant of an already locked-in matrix. The operation will perform work for the next duration microseconds toward the complete matrix operation. duration UDINT The number of microseconds to spend on this calculation. Outputs determinant struct_complexrect The determinant of the matrix. Zero if the calculation is incomplete or the matrix is not invertible. 2015 Schweitzer Engineering Laboratories, Inc. 37

s true if the operation completed. Validates that LockMatrices() has been successfully called. Performs work toward completing the algorithm, in groups of steps, until duration microseconds is exceeded. Decrements duration by the microseconds consumed. s true and outputs the calculated determinant if the operation completed before duration was exhausted. s false and outputs a determinant of zero if LockMatrices() has not been called or duration was exhausted before completing the algorithm. In the case that the matrix is not invertible, outputs a determinant of zero. 5.4.4 UnlockMatrices (Method) This method unlocks any matrices locked by LockMatrices(). It only needs to be called by the user if the matrix operation has been terminated early by calling Clear() on any of the dependent matrices. In all other cases, the matrices will be unlocked on completion of the algorithm. Requests that all locked matrices free themselves for other operations. Sets Busy to false. 5.5 class_matrixgaussianelim (Class) This class handles the locking handshakes and the state required to simplify the matrix to a diagonal ones matrix with trailing columns using Gaussian elimination over the course of multiple scans. The contents of coefficients are destroyed and the contents of solutions are modified by this class. Outputs Busy This class has locked class_matrix instances and is in the middle of a calculation. 2015 Schweitzer Engineering Laboratories, Inc. 38