Matrices Library

mikroPascal PRO for dsPIC30/33 and PIC24 includes a library for operating and working with matrices. All routines work with fractional Q15 format.

Library Routines

Matrix_Transpose

Prototype

procedure Matrix_Transpose(var src, dest: array[1024] of word; numRows, numCols: word);

Description

Function does matrix transposition.

dstM[i][j] = srcM[j][i]

Parameters
  • src: original matrix
  • dest: result matrix
  • numRows: number of rows in the source matrix
  • numCols: number of cols in the source matrix
Returns

Nothing.

Requires

Nothing.

Example
var
  mx1 : array[6] of word;
  mxDest : array[9] of word;
...
Matrix_Transpose(mx1, mxDest, 2, 3);
Notes [W0..W5] used, not restored

Matrix_Subtract

Prototype

procedure Matrix_Subtract(var src1, src2, dest: array[1024] of word; numRows, numCols: word);

Description

Function does matrix subtraction.

dstM[i][j] = srcM1[i][j] - srcM2[i][j]

Parameters
  • src1: first matrix
  • src2: second matrix
  • dest: result matrix
  • numRows: number of rows in the source matrix
  • numCols: number of cols in the source matrix
Returns

Nothing.

Requires

Nothing.

Example
var
  mx1 : array[6] of word;
  mx2 : array[6] of word;
  mxDest : array[9] of word;
...
Matrix_Subtract(mx1, mx2, mxDest, 2, 3);
Notes
  • [W0..W4] used, not restored
  • AccuA used, not restored
  • AccuB used, not restored
  • CORCON saved, used, restored

Matrix_Scale

Prototype

procedure Matrix_Scale(ScaleValue: word; var src1, dest: array[1024] of word; numRows, numCols: word);

Description

Function does matrix scale.

dstM[i][j] = sclVal * srcM[i][j]

Parameters
  • ScaleValue: scale value
  • src1: original matrix
  • dest: result matrix
  • numRows: number of rows in the source matrix
  • numCols: number of cols in the source matrix
Returns

Nothing.

Requires

Nothing.

Example
var
  mx1 : array[6] of word;
  mxDest : array[9] of word;
...
Matrix_Scale(0x4000, mx1, mxDest, 2,3);
Notes
  • [W0..W5] used, not restored
  • AccuA used, not restored
  • CORCON saved, used, restored
  • numRows*numCols < 214
  • Matix members are in Radix Q15 number format.

Matrix_Multiply

Prototype

procedure Matrix_Multiply(var src1, src2, dest: array[256] of word; numRows1, numCols2, numCols1Rows2: word);

Description

Function does matrix multiplication.


with :
i Î [0, numRows1-1]
j Î [0, numCols2-1]
k Î [0, numCols1Rows2-1]

Parameters
  • src1: first matrix
  • src2: second matrix
  • dest: result matrix
  • numRows1: number of rows in the first matrix
  • numCols2: number of columns in the second matrix
  • numCols1Rows2: number of columns in the first matrix and rows in the second matrix
Returns

Nothing.

Requires

Nothing.

Example
var
  mx1 : array[6] of word;
  mx2 : array[6] of word;
  mxDest : array[9] of word;
...
Matrix_Multiply(mx1,mx2,mxDest,2,2,3);
Notes
  • [W0..W7] used, not restored
  • [W8..W13] used, and restored
  • AccuA used, not restored
  • CORCON saved, used, restored
  • Matix members are in Radix Q15 number format.

Matrix_Add

Prototype

procedure Matrix_Add(var src1, src2, dest: array[1024] of word; numRows, numCols: word);

Description

Function does matrix addition.

dstM[i][j] = srcM1[i][j] + srcM2[i][j]

Parameters
  • src1: first matrix
  • src2: second matrix
  • dest: result matrix
  • numRows1: number of rows in the first matrix
  • numCols2: number of columns in the second matrix
Returns

Nothing.

Requires

Nothing.

Example
var
  mx1 : array[6] of word;
  mx2 : array[6] of word;
...
Matrix_Add(mx1,mx2,mxDest,2,3);
Notes
  • [W0..W4] used, not restored
  • AccuA used, not restored.
  • CORCON saved, used, restored.
  • numRows1*numCols2 < 214
Copyright (c) 2002-2012 mikroElektronika. All rights reserved.
What do you think about this topic ? Send us feedback!
Want more examples and libraries? 
Find them on LibStock - A place for the code