TVec.TensorProd Method

Overload List

#SignatureDescription
1TVec TensorProd(TMtx Mtx, TVec Vec, TMtxType MtxType, TMtxOperation Operation)Tensor product between vector and matrix.
2TVec TensorProd(TVec Vec, TMtx Mtx, TMtxType MtxType, TMtxOperation Operation)Calculates the left tensor product between vector and matrix.

Overload 1: TVec TensorProd(TMtx Mtx, TVec Vec, TMtxType MtxType, TMtxOperation Operation)

Tensor product between vector and matrix.

#NameTypeDescription
1MtxTMtxsource TMtx
2VecTVecsource TVec
3MtxTypeTMtxType
4OperationTMtxOperation

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

Remarks:

Calculates the right tensor product between matrix and vector. The result is placed in the calling vector. Depending on the Dew.Math.TMtxType the following operations are available:

  • mtSymmetric: y = alfa*a*x + beta*y
  • mtSymmPosDef: y = alfa*a*x + beta*y
  • mtHermitian: y = alfa*a*x + beta*y
  • mtHermPosDef: y = alfa*a*x + beta*y
  • mtTriangular: y = op(a)*x
  • mtGeneral: y = alfa*op(a)*x + beta*y

The Dew.Math.TMtxVec.Alfa and Dew.Math.TMtxVec.Beta are TVec complex public variables. Their default values are:

  • Alfa = Cplx(1,0)
  • Beta = Cplx(0,0).

Note
Each time you call TensorProd the values of Alfa and Beta are reset to default. If the matrix is not complex, only the real part of Alfa and Beta is used. If matrix complex and symmetric the general type is used.

Examples
TMtx a;
TMtx b;
TMtx c;
TMtx t;
TVec d;
TVec e;
TVec f;
MtxVec.CreateIt(out a, out b, out c, out t);
MtxVec.CreateIt(out d, out e, out f);
try
    {
        // Test non quadratic general matrix
        a.SetIt(2,3,false,[4,3,3,
        3,4,2]);
        e.SetIt(false,new double[] {1,2});
        d.TensorProd(e,a);

        f.SetIt(false,new double[] {10,11,7});
        if !f.Equal(d) then raise Exception.Create(@"Not same");

        // Test on triangular matrices, left
        a.TriangleForm = tfUpper;
        a.TriangleUnit = false;

        a.SetIt(2,2,false,[4,3,
        0,4]);
        e.SetIt(false,new double[] {1,2});
        d.TensorProd(e,a,mtTriangle);

        f.SetIt(false,new double[] {4,11});
        if !f.Equal(d) then raise Exception.Create(@"Not same");

        // Test on triangular matrices, right

        a.TriangleForm = tfUpper; // data to be referenced is in upper triangle
        a.TriangleUnit = false;  // non unit diagonal
        a.SetIt(2,2,false,[4,3,
        0,4]);
        e.SetIt(false,new double[] {1,2});
        d.TensorProd(a,e,mtTriangle);

        f.SetIt(false,new double[] {10,8});
        if !f.Equal(d) then raise Exception.Create(@"Not same");

        // Test on symmetric matrices, right

        a.TriangleForm = tfUpper;
        a.SetIt(2,2,false,[4,3,
        3,4]);
        e.SetIt(false,new double[] {1,2});
        d.TensorProd(e,a,mtSymmetric);

        f.SetIt(false,new double[] {10,11});
        if !f.Equal(d) then raise Exception.Create(@"Not same");

        // Test on symmetric matrices, Left

        a.TriangleForm = tfUpper;
        a.SetIt(2,2,false,[4,3,
        3,4]);
        e.SetIt(false,new double[] {1,2});
        d.TensorProd(a,e,mtSymmetric);

        f.SetIt(false,new double[] {10,11});
        if !f.Equal(d) then raise Exception.Create(@"Not same");
    }
finally
    {
        MtxVec.FreeIt(ref a, ref b, ref c, ref t);
        MtxVec.FreeIt(ref d, ref e, ref f);
    }
See Also: TMtx.TensorProd

Overload 2: TVec TensorProd(TVec Vec, TMtx Mtx, TMtxType MtxType, TMtxOperation Operation)

Calculates the left tensor product between vector and matrix.

#NameTypeDescription
1VecTVecsource TVec
2MtxTMtxsource TMtx
3MtxTypeTMtxType
4OperationTMtxOperation

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