Demonstrates basic matrix and vector operations using the library.
#include <iomanip>
#include <iostream>
{11, 12, 13},
{21, 22, 23},
{31, 32, 33},
};
std::cout << "A = \n" << A << std::endl;
std::cout << "Aᵀ = \n" << AT << std::endl;
std::cout << "AᵀA = \n" << AT * A << std::endl;
Matrix B = A + I * (-R) - 3 * I + E * O * C / 3.14;
std::cout << "B = \n" << B << std::endl;
std::cout << "A(1, 2) = " << A(1, 2) << std::endl;
std::cout <<
"Dimensions of C: " << C.
rows() <<
"×" << C.
cols() <<
"\n"
<<
"Number of elements of C: " << C.
num_elems() <<
"\n"
<< std::endl;
std::iota(std::begin(D), std::end(D), 0.);
std::cout << "D = \n" << D << std::endl;
double D_sum = std::accumulate(std::begin(D), std::end(D), 0.);
std::cout << "Sum of elements of D = " << D_sum << std::endl;
}
std::cout << "v = \n" << v << std::endl;
std::cout << "a = " << a
<< "b = " << b
<<
"a×b = " << a.
cross(b)
<<
"a·b = " << std::setw(15) << a.
dot(b) <<
"\n"
<< std::endl;
std::cout << "v(2) = " << v(2) << "\n" << std::endl;
std::cout << "vvᵀ = \n" << V << std::endl;
std::cout << "vᵀv = " << d << "\n" << std::endl;
}
}
static Matrix constant(size_t rows, size_t cols, double value)
Create a matrix filled with a constant value.
static Matrix identity(size_t rows, size_t cols)
Create an identity matrix.
static Matrix random(size_t rows, size_t cols, double min=0, double max=1, std::default_random_engine::result_type seed=std::default_random_engine::default_seed)
Create a matrix with uniformly distributed random values.
static Matrix zeros(size_t rows, size_t cols)
Create a matrix filled with zeros.
size_t num_elems() const
Get the number of elements in the matrix:
static Matrix ones(size_t rows, size_t cols)
Create a matrix filled with ones.
size_t rows() const
Get the number of rows of the matrix.
size_t cols() const
Get the number of columns of the matrix.
A row vector (1×n matrix).
static RowVector cross(const RowVector &a, const RowVector &b)
Compute the cross product of two 3-vectors.
static double dot(const RowVector &a, const RowVector &b)
Compute the dot product of two vectors.
A column vector (n×1 matrix).
Matrix transpose(const Matrix &in)
Matrix transpose for rectangular or square matrices and row or column vectors.