# Matrix#

## Synopsis#

This will create and display a matrix of NxN dimensions, then multiply it by a vector of N dimension.

## Results#

Output:

```M: 1 2 3
4 5 6
7 8 9

M: 1 2 3
4 5 6
7 8 9

V: [1, 2, 3]
MV: [14, 32, 50]
```

## Code#

### C++#

```#include <itkMatrix.h>
#include <itkVector.h>

#include <iostream>

static void
Construct();
// static void ConstructRunTimeDims();
static void
Multiply();
// static void Inverse();

int
main()
{
Construct();
Multiply();
return EXIT_SUCCESS;
}

void
Construct()
{
using MatrixType = itk::Matrix<double, 3, 3>;
MatrixType M;
M(0, 0) = 1.0;
M(0, 1) = 2.0;
M(0, 2) = 3.0;
M(1, 0) = 4.0;
M(1, 1) = 5.0;
M(1, 2) = 6.0;
M(2, 0) = 7.0;
M(2, 1) = 8.0;
M(2, 2) = 9.0;

std::cout << "M: " << M << std::endl;
}

/*
void ConstructRunTimeDims()
{
int matrixSize = 3;
using MatrixType = itk::Matrix<double, matrixSize, matrixSize>;
MatrixType M;
M(0,0) = 1.0;
M(0,1) = 2.0;
M(0,2) = 3.0;
M(1,0) = 4.0;
M(1,1) = 5.0;
M(1,2) = 6.0;
M(2,0) = 7.0;
M(2,1) = 8.0;
M(2,2) = 9.0;

std::cout << "M: " << M << std::endl;
}
*/

void
Multiply()
{
using MatrixType = itk::Matrix<double, 3, 3>;
MatrixType M;
M(0, 0) = 1.0;
M(0, 1) = 2.0;
M(0, 2) = 3.0;
M(1, 0) = 4.0;
M(1, 1) = 5.0;
M(1, 2) = 6.0;
M(2, 0) = 7.0;
M(2, 1) = 8.0;
M(2, 2) = 9.0;

std::cout << "M: " << M << std::endl;

using VectorType = itk::Vector<double, 3>;
VectorType V;
V[0] = 1.0;
V[1] = 2.0;
V[2] = 3.0;

std::cout << "V: " << V << std::endl;

std::cout << "MV: " << M * V << std::endl;
}

/*
void Inverse()
{

}
*/
```

## Classes demonstrated#

template<typename T, unsigned int NRows = 3, unsigned int NColumns = 3>
class Matrix

A templated class holding a M x N size Matrix.

This class contains a vnl_matrix_fixed in order to make all the vnl mathematical methods available.

ITK Sphinx Examples: