chsvlib
chsv helper source code

◆ Matrix() [2/16]

Matrix ( const value_type value,
size_type  cColumns,
size_type  cRows 
)

Creates a matrix with a specified number of columns and rows such that all elements appertaining to the main diagonal of the created matrix are initialized with a given value.

Parameters
valueis a value to initialize elements of the main diagonal.
cColumnsis a number of columns in the created matrix.
cRowsis a number of rows in the created matrix.

Example code:

#include <iostream>
#include <iomanip>
using namespace Chusov::Math;
template <class val_t, class alloc_t>
std::ostream& operator<<(std::ostream& os, const Matrix<val_t, alloc_t>& m)
{
for (typename Matrix<val_t, alloc_t>::size_type row = 0; row < m.Rows(); ++row)
{
os << "\n[";
for (typename Matrix<val_t, alloc_t>::size_type col = 0; col < m.Columns() - 1; ++col)
os << std::setw(3) << m[col][row] << "\t";
os << std::setw(3) << m[m.Columns() - 1][row] << "]";
}
os << std::endl;
return os;
}
int main(int argc, char** argv)
{
Matrix<int> m1(1, 3, 3); //3-by-3 identity matrix
std::cout << m1 << std::endl;
Matrix<int> m2(1, 3, 4); //3-by-4 matrix with main diagonal elements equal 1
std::cout << m2 << std::endl;
Matrix<int> m3(2, 4, 3); //4-by-3 matrix with main diagonal elements equal 2
std::cout << m3 << std::endl;
}
mathematical and arithmetical functions mostly over integer operands.
MyBase::size_type size_type
An unsigned integral type for sizes within the matrix storage.
Definition: chsvmath.h:6396
A namespace containing mathematical functions and components.
Definition: chsvmath.h:84

Output:

[ 1 0 0]
[ 0 1 0]
[ 0 0 1]
[ 1 0 0]
[ 0 1 0]
[ 0 0 1]
[ 0 0 0]
[ 2 0 0 0]
[ 0 2 0 0]
[ 0 0 2 0]