My Project
Loading...
Searching...
No Matches
Classes | Functions
MatrixVector Namespace Reference

Two dimensional array represents matrix, column and row vector. More...

Classes

class  mat
 
class  row
 
class  vec
 

Functions

template<typename T >
T ** allocateTemp (int ncol, int nrow)
 Allocate ncol, nrow two dimension array for any type, return a pointer.
 
template<typename T >
T ** allocate (int ncol, int nrow)
 Allocate a matrix: height = ncol, width = nrow.
 
template<typename T >
T ** vecVecToArrArr (vector< vector< T > > vv)
 Convert Vector< Vector<T> > to dynamic T**.
 
template<typename T >
vector< vector< T > > arrArrToVecVec (T **arr, int ncol, int nrow)
 Convert T** arr to vector<vector<T>> v2.
 
mat concat (mat m1, mat m2)
 
mat identity (int n)
 
vec backwardSubstitute (mat a, vec b)
 Backward Substitute.
 
mat ltri (mat m, int index)
 Get the L triangle from a matrix.
 
std::pair< mat, matutri (mat m)
 Assume the diagonal entries are not zero, compute the U triangle matrix Lk..(L2 (L1 A))= U TODO: fix the code if a_{ii} = 0.
 
mat geneMat (int ncol, int nrow, int init)
 
mat geneMatRandom (int ncol, int nrow, int fst, int snd)
 Generate random matrix in interval from fst to snd.
 

Detailed Description

Two dimensional array represents matrix, column and row vector.

  1. Good: column vector can be represented as arr[n][0] row vector can be represented as arr[0][n] matrix can be represented as arr[n][m]

Function Documentation

◆ allocate()

template<typename T >
T ** MatrixVector::allocate ( int  ncol,
int  nrow 
)

Allocate a matrix: height = ncol, width = nrow.

Parameters
ncolis the height of matrix
nrowis the width of matrix
Returns
T**

◆ allocateTemp()

template<typename T >
T ** MatrixVector::allocateTemp ( int  ncol,
int  nrow 
)

Allocate ncol, nrow two dimension array for any type, return a pointer.

Parameters
ncolis number of column
nrowis number of row
Returns
T**

TODO: Change ncol => width nrow => heigh

Parameters
ncolis number of column
nrowis number of row
Returns
T**

◆ arrArrToVecVec()

template<typename T >
vector< vector< T > > MatrixVector::arrArrToVecVec ( T **  arr,
int  ncol,
int  nrow 
)

Convert T** arr to vector<vector<T>> v2.

int ncol = 2;
int nrow = 3;
int arr[2][3] = {
{1, 2, 3},
{4, 5, 6}
};
vector<vector<int>> v3 = {
{1, 2, 3},
{4, 5, 6}
};
int* pt = &arr[0][0];
vector<vector<int>> vv = arrArrToVecVec<int>(&pt, ncol, nrow);
assert(arr[0][0] == v3[0][0]);
assert(arr[0][1] == v3[0][1]);
assert(arr[0][2] == v3[0][2]);
assert(arr[1][0] == v3[1][0]);
assert(arr[1][1] == v3[1][1]);
assert(arr[1][2] == v3[1][2]);

Use std::move() ?

int ncol = 2;
int nrow = 3;
int arr[2][3] = {
{1, 2, 3},
{4, 5, 6}
};
vector<vector<int>> v3 = {
{1, 2, 3},
{4, 5, 6}
};
int* pt = &arr[0][0];
vector<vector<int>> vv = arrArrToVecVec<int>(&pt, ncol, nrow);
assert(arr[0][0] == v3[0][0]);
assert(arr[0][1] == v3[0][1]);
assert(arr[0][2] == v3[0][2]);
assert(arr[1][0] == v3[1][0]);
assert(arr[1][1] == v3[1][1]);
assert(arr[1][2] == v3[1][2]);

Use std::move() ?

◆ backwardSubstitute()

vec MatrixVector::backwardSubstitute ( mat  a,
vec  b 
)

Backward Substitute.

Parameters
[int]a - upper triangle
[int]b - column vector
Returns
column vector x

\[ Ax = b \]

a11 a12 a13 x[0] = b[0]
a22 a23 x[1] = b[1]
a33 x[2] = b[2]
Parameters
[int]a - upper triangle
[int]b - column vector
Returns
column vector x

\[ Ax = b \]

a11 a12 a13 x[0] = b[0]
a22 a23 x[1] = b[1]
a33 x[2] = b[2]

◆ geneMatRandom()

mat MatrixVector::geneMatRandom ( int  ncol,
int  nrow,
int  fst,
int  snd 
)

Generate random matrix in interval from fst to snd.

◆ ltri()

mat MatrixVector::ltri ( mat  m,
int  index 
)

Get the L triangle from a matrix.

\[ \begin{equation} \begin{aligned} &v_k = \begin{bmatrix} 0 \\ \vdots \\ 0 \\ l_{k+1,k} \\ l_{k+2,k} \\ \vdots \\ l_{m,k} \\ \end{bmatrix} \\ &v_k e_{k}^{*} = \begin{bmatrix} 0 & & & & \\ & \ddots & & & \\ & & 0 & & \\ & & l_{k+1,k} & & \\ & & \vdots & \ddots & \\ & & l_{m,k} & & 0 \\ \end{bmatrix} \\ \end{aligned} \end{equation} \]

Ref

\[ \begin{equation} \begin{aligned} &v_k = \begin{bmatrix} 0 \\ \vdots \\ 0 \\ l_{k+1,k} \\ l_{k+2,k} \\ \vdots \\ l_{m,k} \\ \end{bmatrix} \\ &v_k e_{k}^{*} = \begin{bmatrix} 0 & & & & \\ & \ddots & & & \\ & & 0 & & \\ & & l_{k+1,k} & & \\ & & \vdots & \ddots & \\ & & l_{m,k} & & 0 \\ \end{bmatrix} \\ \end{aligned} \end{equation} \]

Ref

◆ vecVecToArrArr()

template<typename T >
T ** MatrixVector::vecVecToArrArr ( vector< vector< T > >  vv)

Convert Vector< Vector<T> > to dynamic T**.

Parameters
vvis vector of vector type.
Returns
T type of two dimensions array