﻿ 20-sim webhelp > Language Reference > Matrices and Vectors > Use

Use

Matrices and Vectors can be used in equations just like scalars. If possible, the element notation can be left out. If equations get ambiguous, element notation must be used!

Whole matrix or vector

K = 1; // Make all elements of K equal to 1.

M = C; // Make matrix M equal to matrix C (sizes have to be equal).

N = D*inverse(L); // Make matrix N equal to the matrix product of D

// and the inverse of L (sizes of N, D and L have to be equal).

Matrix and vector elements

N = [sin(time),cos(time);cos(time),-sin(time)]; // Make elements of N equal to functions.

L = time; // Make element 4 of columned L equal to time.

D[2,5] = A[2,2]*B[1,1]; // Declare one element

Multiple elements (ranges)

To prevent multiple equations for assigning matrix elements, ranges can be assigned using a colon. E.g. 1:5 means element 1 to 5, 7:8 means element 7 and 8. Backward counting ranges (like 10:1) are not allowed!

D[2,1:5] = A[1,1:5]; // D[2,1] = A[1,1], ... , D[2,5] = A[1,5]

variables

real v,p[6,6];

equations

v = p[4:6,6]; // v = p[4,6], ... , v = p[6,6]

Operators

Some scalar operators can also be used for matrices and vectors. Depending on the specific operator, the meaning may differ for scalars, vectors and matrices.

 Operator Description * Multiplication + Addition - Subtraction .* ArrayMultiplication ./ ArrayDivision .^ ArrayPower / Division ^ Power - Prefix Minus Sign + Prefix Plus Sign | .. | Absolute / Determinant / Norm

Functions

A lot of special matrix and vector functions are supported in 20-sim:

 Function Description Adjoint adjoint Antisym Columns Cross Determinant Diag Eye Homogeneous Inner Inverse InverseH Linsolve Max Min Msum Norm Norminf Rows Skew Sym Tilde Trace Transpose