Overload List
| # | Signature | Description |
|---|---|---|
| 1 | function MulElem(const Mtx: TMtx): TMtx; | Matrix element-wise 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): TMtx; | self = X*Y*zScalar |
| 4 | function MulElem(const X: TMtxVec; const Y: TMtxVec; const Z: TMtxVec): TMtx; | self = X*Y*Z |
| 5 | function MulElem(const X: TMtxVec; const Y: TMtxVec; const Z: Double): TMtx; | self = X*Y*zScalar |
Overload 1: function MulElem(const Mtx: TMtx): TMtx;
Matrix element-wise 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 TMtx.Rows, TMtx.Cols and TMtxVec.Complex properties of both matrices must match, otherwise an exception is raised.
var A,B,C: TMtx;
begin
CreateIt(A,B,C);
try
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]
finally
FreeIt(A,B,C);
end;
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 TMtx.Rows, TMtx.Cols and TMtxVec.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 excetion is raised. 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): TMtx;
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
Overload 4: function MulElem(const X: TMtxVec; const Y: TMtxVec; const Z: TMtxVec): TMtx;
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;
Overload 5: function MulElem(const X: TMtxVec; const Y: TMtxVec; const Z: Double): TMtx;
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;