Overload List
| # | Signature | Description |
|---|---|---|
| 1 | function MulElem(const Mtx: TMtx): TMtx; | Matrix array multiplication. |
| 2 | function MulElem(const Mtx1: TMtx; const Mtx2: TMtx): TMtx; | Multiplies elements in Mtx1 matrix with the elements in Mtx2 matrix (array multiplication) and stores the results in calling matrix. |
| 3 | function MulElem(const X: TMtxVec; const Y: TMtxVec; const Z: TCplx): TMtxVec; | self = X*Y*zScalar |
| └ indexed: function MulElem(const X: TMtxVec; XIndex: Integer; const Y: TMtxVec; YIndex: Integer; const Z: TCplx; Index: Integer; Len: Integer): TMtxVec; | ||
| 4 | function MulElem(const X: TMtxVec; const Y: TMtxVec; const Z: TMtxVec): TMtxVec; | self = X*Y*Z |
| └ indexed: function MulElem(const X: TMtxVec; XIndex: Integer; const Y: TMtxVec; YIndex: Integer; const Z: TMtxVec; zIndex: Integer; Index: Integer; Len: Integer): TMtxVec; | ||
| 5 | function MulElem(const X: TMtxVec; const Y: TMtxVec; const Z: Double): TMtxVec; | self = X*Y*zScalar |
| └ indexed: function MulElem(const X: TMtxVec; XIndex: Integer; const Y: TMtxVec; YIndex: Integer; const Z: Double; Index: Integer; Len: Integer): TMtxVec; |
Overload 1: function MulElem(const Mtx: TMtx): TMtx;
Matrix array multiplication.
| # | Name | Type | Description |
|---|---|---|---|
| 1 | Mtx | TMtx |
Result: stored in self (calling object), returns self for chaining
Multiplies elements in Mtx matrix with the elements in the calling matrix (array multiplication) and stores the results in calling matrix. The Matrix.Rows, Matrix.Cols and Matrix.Complex properties of both matrices must match, otherwise an exception is raised.
var A,B,C: Matrix;
begin
A.SetIt(2,2,False,[1,2,
2,4]);
B.SetIt(2,2,False,[1,2,
2,4]);
C.MulElem(A,B);
// C becomes:
// [1, 4,
// 4,16]
end;
var
a, b, expected: Matrix;
begin
a := [[1.0, 2.0], [3.0, 4.0]];
b := [[5.0, 6.0], [7.0, 8.0]];
a.MulElem(b);
expected := [[5.0, 12.0], [21.0, 32.0]];
if not a.IsEqual(expected, 1e-10, TCompare.cmpAbsolute) then
raise Exception.Create('Matrix.MulElem: mismatch');
end;
Overload 2: function MulElem(const Mtx1: TMtx; const Mtx2: TMtx): TMtx;
Multiplies elements in Mtx1 matrix with the elements in Mtx2 matrix (array multiplication) and stores the results in calling matrix.
Result: stored in self (calling object), returns self for chaining
The Matrix.Rows, Matrix.Cols and Matrix.Complex properties of calling matrix are set implicitly to match those of Mtx1 and Mtx2 matrices. Mtx1 and Mtx2 Rows, Cols, and Complex properties must be the same, otherwise an exception is raised.
var
a, x, y, expected: Matrix;
begin
x := [[1.0, 2.0], [3.0, 4.0]];
y := [[5.0, 6.0], [7.0, 8.0]];
a.MulElem(x, y);
expected := [[5.0, 12.0], [21.0, 32.0]];
if not a.IsEqual(expected, 1e-10, TCompare.cmpAbsolute) then
raise Exception.Create('Matrix.MulElem: mismatch');
end;
Overload 3: function MulElem(const X: TMtxVec; const Y: TMtxVec; const Z: TCplx): TMtxVec;
Compute X*Y*zScalar
Result: stored in self (calling object), returns self for chaining
The following expression would also run at the same or higher speed, when passing X also for the Z parameter:
X^2*zScalar
Indexed: function MulElem(const X: TMtxVec; XIndex: Integer; const Y: TMtxVec; YIndex: Integer; const Z: TCplx; Index: Integer; Len: Integer): TMtxVec;
Compute X*Y*zScalar on sub array
| # | Name | Type | Description |
|---|---|---|---|
| 1 | X | TMtxVec | |
| 2 | XIndex | Integer | X start index |
| 3 | Y | TMtxVec | |
| 4 | YIndex | Integer | Y start index |
| 5 | Z | TCplx | |
| 6 | Index | Integer | start index |
| 7 | Len | Integer | element count |
Result: stored in self (calling object), returns self for chaining
Overload 4: function MulElem(const X: TMtxVec; const Y: TMtxVec; const Z: TMtxVec): TMtxVec;
Compute X*Y*Z
Result: stored in self (calling object), returns self for chaining
The following expression would also run at the same or higher speed, when passing X also for the Z parameter:
X^2*Y
uses MtxVec, MtxExpr, Math387;
var
X, Y, Z, A1, A2, A3: Vector;
begin
X := [1,2,3,4];
Y := [2,3,4,5];
Z := [3,4,5,6];
A1 := X * Y * Z;
A2 := MulElem(X, Y, Z);
A3.Mul(X, Y, Z);
if not A2.IsEqual(A1) then ERaise('Problem');
if not A3.IsEqual(A1) then ERaise('Problem');
end;
Indexed: function MulElem(const X: TMtxVec; XIndex: Integer; const Y: TMtxVec; YIndex: Integer; const Z: TMtxVec; zIndex: Integer; Index: Integer; Len: Integer): TMtxVec;
Compute X*Y*Z on sub array
| # | Name | Type | Description |
|---|---|---|---|
| 1 | X | TMtxVec | |
| 2 | XIndex | Integer | X start index |
| 3 | Y | TMtxVec | |
| 4 | YIndex | Integer | Y start index |
| 5 | Z | TMtxVec | |
| 6 | zIndex | Integer | |
| 7 | Index | Integer | start index |
| 8 | Len | Integer | element count |
Result: stored in self (calling object), returns self for chaining
Overload 5: function MulElem(const X: TMtxVec; const Y: TMtxVec; const Z: Double): TMtxVec;
Compute X*Y*zScalar
Result: stored in self (calling object), returns self for chaining
The following expression would also run at the same or higher speed, when passing X also for the Z parameter:
X^2*zScalar
uses MtxVec, MtxExpr, Math387;
var
X, Y, A1, A2, A3: Vector;
zScalar: Double;
begin
zScalar := 2.0;
X := [1,2,3,4];
Y := [2,3,4,5];
A1 := (X * Y) * zScalar;
A2 := MulElem(X, Y, zScalar);
A3.Mul(X, Y, zScalar);
if not A2.IsEqual(A1) then ERaise('Problem');
if not A3.IsEqual(A1) then ERaise('Problem');
end;