TMtx.Diag Method

TMtx Diag(TVec Vec, Int32 k)

Sets the matrix diagonal to values from the vector.

#NameTypeDescription
1VecTVecsource TVec
2kInt32

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

Remarks:

Sets the k-th diagonal of the calling matrix to values from from the Vec object. If k = 0 then the main diagonal matrix is set, if k < 0 then the k-th subdiagonal matrix is set and if k > 0 the then the k-th super diagonal is set. The matrix must be large enough to hold diagonal or an exception is raised.

Examples
TMtx A;
TVec D;
MtxVec.CreateIt(out A);
MtxVec.CreateIt(out D);
try
    {
        A.SetIt(2,2,true,[1,1, 2,1,
        1,2, 2,2]);
        D.SetIt(2,  true,new double[] {2,2, 1,1});
        A.Diag(D,0);
        // A becomes:
        // [2,2, 2,1]
        // [1,2, 1,1]
    }
finally
    {
        MtxVec.FreeIt(ref D);
        MtxVec.FreeIt(ref A);
    }
See Also: TVec.Diag