NABLA  Nabla Ain't Basic Linear Algebra

In the code below m is a matrix , v is a vector and s is a scalar.


vector<double> v, //default
v1(3), //initial size
v2(3, 1.), //initial size and value
v3(v2), //copy
v4(v2 + v3); //from vector expression
matrix<double> m, //default
m1(3, 3), //initial size
m2(3, 3, 1.), //initial size and value
m3(m2), //copy
m4(m2 + m3); //from matrix expression

Element access:

m(0, 0);

Access to matrix rows and columns:

column(m, 0); //reference to matrix column (as column vector)
row(m, 1); //reference to matrix row (as row vector)

Basic linear algebra operations:

v = +v1; //element-wise plus
v = -v1; //element-wise minus
v = conj(v1); //element-wise conjugation
v = v1 + v2; //element-wise addition
v = v1 - v2; //element-wise subtraction
v = v1*s; //scaling
v = s*v1; //scaling
v += v1; //addition assignment
v -= v1; //subtraction assignment
v *= s; //scaling assignment
v = mul(v1, v2); //element-wise multiplication
v = div(v1, v2); //element-wise division
m = +m1; //element-wise plus
m = -m1; //element-wise minus
m = conj(m1); //element-wise conjugation
m = m1 + m2; //element-wise addition
m = m1 - m2; //element-wise subtraction
m = m1*s; //scaling
m = s*m1; //scaling
m += m1; //addition assignment
m -= m1; //subtraction assignment
m *= m1; //multiplication assignment
m = mul(m1, m2); //element-wise multiplication
m = div(m1, m2); //element-wise division
m = m1*m2; //matrix multiplication
v = m*v; //matrix-vector multiplication (linear transform or map)

Some common algorithms:

s = sum_of_products(v1, v2); //sum of product of corresponding elements
s = dot_product(v1, v2); //dot product (inner product in Euclidean space)
v = cross_product(v1, v2); //cross product (exterior or wedge product in R^3 space)
s = norm(v); //Euclidean norm
m = transpose(m); //matrix transposition
m = invert(m); //matrix inversion

Some extended features:

m = v; //implicitly treating vectors as matrices
m = m1[0]; //implicitly treating vectors (matrix rows) as matrices
matrix<double, lower_tr> m1, //default construction
m2(3), //construction with initial size
m3(3, 1.); //construction with initial size and value
matrix<double> m;
m1 = m2*m3; //handling of shaped expressions
m1 = m2*reshape<lower_tr>(m); //reshaping expressions