Matrix.MulElem Method

Overload List

#SignatureDescription
1function MulElem(const Mtx: TMtx): TMtx;Matrix array multiplication.
2function 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.
3function 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;
4function 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;
5function 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.

#NameTypeDescription
1MtxTMtx

Result: stored in self (calling object), returns self for chaining

Remarks:

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.

Examples
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;
See Also: Matrix.InvElem

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.

#NameTypeDescription
1Mtx1TMtx
2Mtx2TMtx

Result: stored in self (calling object), returns self for chaining

Remarks:

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.

Examples
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

#NameTypeDescription
1XTMtxVec
2YTMtxVec
3ZTCplx

Result: stored in self (calling object), returns self for chaining

Remarks:

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

#NameTypeDescription
1XTMtxVec
2XIndexIntegerX start index
3YTMtxVec
4YIndexIntegerY start index
5ZTCplx
6IndexIntegerstart index
7LenIntegerelement 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

#NameTypeDescription
1XTMtxVec
2YTMtxVec
3ZTMtxVec

Result: stored in self (calling object), returns self for chaining

Remarks:

The following expression would also run at the same or higher speed, when passing X also for the Z parameter:

X^2*Y

Examples
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

#NameTypeDescription
1XTMtxVec
2XIndexIntegerX start index
3YTMtxVec
4YIndexIntegerY start index
5ZTMtxVec
6zIndexInteger
7IndexIntegerstart index
8LenIntegerelement 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

#NameTypeDescription
1XTMtxVec
2YTMtxVec
3ZDouble

Result: stored in self (calling object), returns self for chaining

Remarks:

The following expression would also run at the same or higher speed, when passing X also for the Z parameter:

X^2*zScalar

Examples
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;

Indexed: function MulElem(const X: TMtxVec; XIndex: Integer; const Y: TMtxVec; YIndex: Integer; const Z: Double; Index: Integer; Len: Integer): TMtxVec;

Compute X*Y*zScalar on sub array

#NameTypeDescription
1XTMtxVec
2XIndexIntegerX start index
3YTMtxVec
4YIndexIntegerY start index
5ZDouble
6IndexIntegerstart index
7LenIntegerelement count

Result: stored in self (calling object), returns self for chaining