Matrices Library

mikroBasic 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

sub procedure Matrix_Transpose(dim byref src, dest as word[1024], dim numRows, numCols as 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
dim
  mx1 as word[6]
  mxDest as word[9]
...
Matrix_Transpose(mx1, mxDest, 2, 3)
Notes [W0..W5] used, not restored

Matrix_Subtract

Prototype

sub procedure Matrix_Subtract(dim byref src1, src2, dest as word[1024], dim numRows, numCols as 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
dim
  mx1 as word[6]
  mx2 as word[6]
  mxDest as word[9]
...
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

sub procedure Matrix_Scale(dim ScaleValue as word, dim byref src1, dest as word[1024], dim numRows, numCols as 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
dim
  mx1 as word[6]
  mxDest as word[9]
...
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

sub procedure Matrix_Multiply(dim byref src1, src2, dest as word[256], dim numRows1, numCols2, numCols1Rows2 as 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
dim
  mx1 as word[6]
  mx2 as word[6]
  mxDest as word[9]
...
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

sub procedure Matrix_Add(dim byref src1, src2, dest as word[1024], dim numRows, numCols as 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
dim
  mx1 as word[6]
  mx2 as word[6]
  mx3 as word[6]
...
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