Matrix, Array and Data Structure Functions

Parent Previous Next

VisualSim                                                                                                                                    

Matrix, Array and Data Structure Functions

 

Function, Argument Type(s) & Return Type

 

Description

 

 Example

arrayToMatrix

{type}, int, int

Return Type: [type]

Create a matrix from the specified array with the specified number of rows and columns.


a = {1,2,3,4}

x = arrayToMatrix(a,2,2)

  = [ 1, 2; 3, 4]

conjugateTranspose

[complex]

Return Type: [complex]

Return the conjugate transpose of the specified matrix.

m1 = [1, 2; 3, 4]

x = conjugateTranspose(m1)

  = [1.0+0.0i, 3.0+0.0i;

     2.0+0.0i, 4.0+0.0i]

createSequence

type, type, int

Return Type: {type}         

Create an array with values starting with the first argument, incremented by the second argument, of length given by the third argument.


 

   x = createSequence (3, 2, 4)

    = {3, 5, 7, 9}

crop

[int], int, int, int, int / [double], int, int, int, int / [complex], int, int, int, int / [long], int, int, int, int

Return Type: [int] / [double] / [complex] / [long]

Given a matrix of any type, return a submatrix starting at the specified row and column with the specified number of rows and columns.



m1 = [ 1, 2, 3; 4, 5, 6; 7, 8, 9]

x = crop(m1,0,1,2,1)

  = [2; 5]

determinant

[double] / [complex]

Return Type: double / complex

Return the determinant of the specified matrix.


m1 = [2, 6, 3; 1, 3, 9; 7, 8, 4]

x = determinant(m1)

  = 195.0

diag

{type}

Return Type: [type]

Return a diagonal matrix with the values along the diagonal given by the specified array.

diag (int)

   = [0] 

  diag(long)

   = [0L]

  diag(double)

   = [0.0]

divideElements

[type], [type]

Return Type: [type]

Return the element-by-element division of two matrices.

a = [1,0,0;0,1,0;0,0,1]

b = [1,2,3;4,5,6;7,8,9]

x = divideElements(a,b)

  = [1, 0, 0; 0, 0, 0; 0, 0, 0]

find

{type}, type

Return Type: {int}

Return an array of the indices where elements of the specified array match the specified token.

Array = {1,2,3,4,2,6,7}

X = find(Array,2)

  = {1,4}



find

{boolean}

Return Type: {int}

Return an array of the indices where elements of the specified array have value true.


Array = {false, true, false, false, true}

X = find(Array)

   = {1,4}

find

{type}, type, int

Return Type: {int}

Return an array of the indices where elements of the specified array match the specified token and starts from the index (int).  


Array = {false,true,false,true,false}

X = find(Array,false,2)

  = {2,4,0}

hilbert

int

Return Type: {double}

Return a square Hilbert matrix, where. A Hilbert matrix is nearly, but not quite singular.


 hilbert(2)

 = [1.0, 0.5; 0.5, 0.33]

identityMatrixComplex

int

Return Type: {complex}

Return an identity matrix with the specified dimension.


identityMatrixComplex(2)

= [1.0 + 0.0i,  0.0 + 0.0i;

   0.0 + 0.0i,  1.0 + 0.0i ]


identityMatrixDouble

int

Return Type: [double]

Return an identity matrix with the specified dimension.


 identityMatrixDouble(2)

 = [1.0, 0.0; 

    0.0, 1.0]

identityMatrixInt

int

Return Type: {int}

Return an identity matrix with the specified dimension.


 identityMatrixInt(2)

 = [1, 0; 0, 1]

identityMatrixLong

int

Return Type: [long]

Return an identity matrix with the specified dimension.


 identityMatrixLong(2)

 = [1L, 0L; 0L, 1L]

intersect

data structure, data structure

Return Type: data structure

Return a data structure that contains only fields that are present in both arguments, where the value of the field is taken from the first data structure.

a = {src = "s1",des = "d1",          priority = 1}

b = {src = "s2",des = "d1",          priority = 2,msg = "Hi"}

x = intersect(a,b)

  = {des = "d1", priority = 1,      src = "s1"}


inverse

{double] / [complex]

Return Type: [double] / [complex]

Return the inverse of the specified matrix, or throw an exception if it is singular.

m1 = [2,6,3;1,3,9;7,8,4]

inverse(m1)

= [-0.3,  -0.0,   0.23;

   0.3,  -0.067, -0.07;

  -0.06, 0.13,  6.9E-18]

matrixToArray

[type]

Return Type: {type}

Create an array containing the values in the matrix.

a1 = [1, 2, 3; 4, 5, 6; 7, 8, 9]

matrixToArray(a1)

= {1, 2, 3, 4, 5, 6, 7, 8, 9}

merge

data structure, data structure

Return Type: data structure

Merge two data structures, giving priority to the first one when they have matching data structure labels.

a = {src = "s1",dest =              "d1",priority = 1}

b = {src = "s2",dest =              "d1",priority = 2, msg = "hi"}

x = merge(a,b)

  = {src = "s1",dest =              "d1",priority = 1,msg = "hi"}

 

multiplyElements

[type], [type]

Return Type: [type]

Multiply element wise the two specified matrices.

a = [1,0,0;0,1,0;0,0,1]

b = [1,2,3;4,5,6;7,8,9]

multiplyElements(a,b)

= [1, 0, 0; 0, 5, 0; 0, 0, 9]

OrthogonalizeColumns

[double] / [complex]

Return Type: [double] / [complex]

Return a similar matrix with orthogonal columns.


a = [1.0,2.0;3.0,4.0]

x = orthogonalizeColumns(a)

  = [1.0, 0.59; 3.0, -0.2]

orthogonalizeRows

[double] / [complex]

Return Type: [double] / [complex]

Return a similar matrix with orthogonal rows.

a = [1.0,2.0;3.0,4.0]

x = orthogonalizeRows(a)

  = [1.0, 2.0; 0.79, -0.4]

OrthonormalizeColumns

[double] / [complex]

Return Type: [double] / [complex]

Return a similar matrix with orthonormal columns.

a = [1.0,2.0;5.0,6.0]

x = orthonormalizeColumns(a)

  = [1.0, 0.76; 5.0, -0.15]

orthonormalizeRows

[double] / [complex]

Return Type: [double] / [complex]

Return a similar matrix with orthonormal rows.

a = [1.0,2.0;5.0,6.0]

x = orthonormalizeRows(a)

  = [0.44, 0.89; 0.89, -0.44]

repeat

int, type

Return Type: {type}

Create an array by repeating the specified token the specified number of times.

a = {1, 2, 3, 4}

  x = repeat(a,2)

  = {{2},{2,2},{2,2,2},              {2,2,2,2}}

sort

{string}/ {realScalar}

Return Type: {string} / {realScalar}

Return the specified array, but sorted in ascending order. realScalar is any scalar token except complex.


a = {5.0, 2.0, 8.0, 4.0}

x = a.sort()

  = {2.0, 4.0, 5.0, 8.0}

sortAscending

{string}/{realScalar}

Return Type: {string} / {realScalar}

Return the specified array, but sorted in ascending order. realScalar is any scalar token except complex.


a = {6, 4, 7, 9, 2, 1, 5, 3}

x = sortAscending(a)

  = {1, 2, 3, 4, 5, 6, 7, 9}

sortDescending

{string}/ {realScalar}

Return Type: {string} / {realScalar}

Return the specified array, but sorted in descending order. realScalar is any scalar token except complex.


a = {6, 4, 7, 9, 2, 1, 5, 3}

x = sortDescending(a)

  = {9, 7, 6, 5, 4, 3, 2, 1}

Subarray

{type}, int, int

Return Type: {type}

Extract a subarray starting at the specified index with the specified length.

a = {1,2,3,4,5,6,7,8,9}

x = subarray(a,2,4)

  = {3, 4, 5, 6}

sum

{type} / [type]

Return Type: type

Sum the elements of the specified array / matrix. This throws an exception if the elements do not support addition or if the array is empty (an empty matrix will return zero).



a = [1, 2, 3; 4, 5, 6; 7, 8, 9]

x = sum(a)

  = 45

trace

[type]

Return Type: type

Return the trace of the specified matrix.

a = [1,2;5,6]

x = trace(a)

  = 7

transpose

[type]

Return Type: [type]

Return the transpose of the specified matrix.

 a = [1,2,3; 4,5,6; 7,8,9]

 x = transpose(a)

   = [1, 4, 7;   2, 5, 8; 3, 6, 9]

zeroMatrixComplex

int, int

Return Type: [complex]

Return a zero matrix with the specified number of rows and columns.

   zeroMatrixComplex(2,2)

 = [0.0 + 0.0i, 0.0 + 0.0i;

    0.0 + 0.0i, 0.0 + 0.0i]

zeroMatrixDouble

int, int

Return Type: [double]

Return a zero matrix with the specified number of rows and columns.

  zeroMatrixDouble(2,2)

  = [0.0, 0.0; 0.0, 0.0]

zeroMatrixInt

int, int

Return Type: [int]

Return a zero matrix with the specified number of rows and columns.

  

  zeroMatrixInt(2,2)

  = [0, 0; 0, 0]

zeroMatrixLong

int, int

Return Type: [long]

Return a zero matrix with the specified number of rows and columns.


  zeroMatrixLong(2,2)

  = [0L, 0L; 0L, 0L]

 

 

Created with the Personal Edition of HelpNDoc: Free iPhone documentation generator