TSparseMtx::Diag Method

void Diag(TVec *Vec, int kk = 0);

Copies the kk-th diagonal of TSparseMtx to the Vec object.

#NameTypeDescription
1VecTVec *
2kk = 0int
Remarks:

Copies the kk-th diagonal of TSparseMtx to the Vec object. If k = 0 then the main diagonal matrix is obtained, if k < 0 then the k-th subdiagonal matrix is obtained and if k > 0 the then the k-th super diagonal is copied to Vec. The Vec parameters size is set automatically.

Examples
#include "MtxExpr.h"
#include "sparse.h"

using namespace Dew;
using namespace Dew::Math;

void Example()
{
    Vector d(0);
    TSparseMtx* asp = new TSparseMtx();
    TSparseMtx* bsp = new TSparseMtx();
    TSparseMtx* csp = new TSparseMtx();
    TSparseMtx* dsp = new TSparseMtx();
    // ...
    Matrix A = {{4, 1, 0}, {2, 5, 3}, {0, 1, 6}};
    asp->DenseToSparse(A);
    // #1 : split asp into lower(bsp), upper(csp) and diagonal(d) sections
    bsp->LowerTriangle(asp);
    csp->UpperTriangle(asp);
    asp->Diag(d);
    // now combine lower(bsp), upper, and diagonal(d) back
    dsp->AddSplit(bsp, d, csp);
    delete asp;
    delete bsp;
    delete csp;
    delete dsp;
}
Declared in Dew::Math::TSparseMtx · Dew.Math/sparse.h · Cross-compiler