A Delphi record wrapper around IMatrix from MrMath by MrMath (Michael Rabat), adding operator overloading and a cleaner API.
Requires MrMath — add Matrix.pas (and its dependencies) to your project.
| Feature | Example |
|---|---|
| Arithmetic operators | C := A + B, A * 2.0, -A, A / 3.0 |
| Matrix multiplication | C := A * B |
| Element-wise multiply | C := A.MultiElementweise(B) |
| Implicit conversions | TMatrix ↔ IMatrix ↔ TMatrixArray |
| Index access | M[col, row] := 1.5 |
uses tools.Matrix;
var
A, B, C: TMatrix;
begin
// Create and fill
A := TMatrix.Create(2, 2);
A[0,0] := 1; A[1,0] := 2;
A[0,1] := 3; A[1,1] := 4;
// Identity matrix
B := TMatrix.CreateEye(2);
// Operators
C := A + B; // addition
C := A * 2.5; // scalar multiply
C := A * B; // matrix multiply
C := A.Transpose; // transpose
end;// 2x + y = 5
// x + 3y = 10 → x=1, y=3
var
M: TMatrix;
b, x: TMatrixArray;
IsSingular: Boolean;
begin
M := TMatrix.Create(2, 2);
M[0,0] := 2; M[1,0] := 1;
M[0,1] := 1; M[1,1] := 3;
b := TMatrixArray.Create(5, 10);
x := M.Solve(b, IsSingular);
if not IsSingular then
Writeln(x[0]:0:4, ' ', x[1]:0:4); // 1.0000 3.0000
end;M.AddRow(0.0); // append a row filled with 0
M.InsertCol(1, 1.0); // insert column at index 1 filled with 1
M.DeleteRow(2); // remove row at index 2
M.SetRow(0, 99.0); // set entire row 0 to a constantif not M.IsSymmetric then
M := M.ToSymMatrix; // mirror lower triangle to upperAdd tools.Matrix.Test.pas to a DUnitX console project and run. All 35 tests should pass.
Mozilla Public License 2.0 — same as the underlying MrMath library.