Basic Matrix operation in Lazarus/FreePascal

Well.. This is my first post about FreePascal (FPC)/Lazarus. I’ve been asked to create a simulation for artificial neural-network using backpropagation without using Matlab. So, I decided to use FreePascal/Lazarus to create it. Why? Because it’s challenging.. 😀

First problem that I need to overcome is how to mimic matrix arithmetic in FreePascal just like in Matlab. So, after some searching, I found satisfactory library called DynMatrix.

Download file from here:

Extract two files inside the archive, you’ll need only: dynmatrixutils.pas and dynmatrix.pas.

Use these two files in your project/form, example:

Now, for the example usage:
Declare a matrix variables:

Init a matrix into all zeros with 4 rows and 3 cols:

Setting a value for an element in matrix:

Getting the value of an element:

Matrix addition, subtraction, multiplication and matrix power:

Matrix transpose, inverse and convolution

Converting string to matrix:

Creating “eye” matrix:

Does this library also works on Delphi? Although I have Delphi, I haven’t tried it. So, no idea, but I’ve been looking at the source code and it seems it is OK to use it on Delphi Pascal. The dependecies is only on SysUtils, math and Classes

Leave a Reply

%d bloggers like this: