Skip to content

GetStarted

itu-itis21-altiparmak20 edited this page Apr 7, 2022 · 1 revision

Necessary Packages

cmake
make

Installation

$ git clone https://github.com/CihatAltiparmak/Matrix.git
$ cd Matrix
$ mkdir build && cd build
$ cmake ..
$ sudo make install

Creating Matrix and Basic Usage

We create the matrices by passing argument as much as you want as following

#include <atrix/matrix.h>
#include <iostream>

int main() {

    // we create the matrix with dimension 5x6 
    Matrix::Matrix<double> A(5, 6);

    // we create the another matrix with dimension 2x2x3x4
    Matrix::Matrix<double> B(2, 2, 3, 4);

    // we can also create the new matrix by deep-copying  another matrix
    Matrix::Matrix<double> C(A);

    // we can assign a matrix to another matrix
    Matrix::Matrix<double> D = A;
}

We can access to the elements of the matrix as following. The elements of matrix defaultly are initialized from 0 to matrix_size - 1 respectively

#include <atrix/matrix.h>
#include <iostream>

int main() {

    // we create the matrix with dimension 5x6 
    Matrix::Matrix<double> A(5, 6);

    for (int i = 0; i < 5; i++) {
        for (int j = 0; j < 6; j++)
            // It's same as  A[i][j] 
            std::cout << A(i, j) << " ";

        std::endl;
    } 
}

Outputs Here

0 1 2 3 4 5
6 7 8 9 10 11
12 13 14 15 16 17
18 19 20 21 22 23
24 25 26 27 28 29

Now, let's change the value of A[i][j]

#include <atrix/matrix.h>
#include <iostream>

int main() {

    // we create the matrix with dimension 5x6 
    Matrix::Matrix<double> A(5, 6);

    // we change the value of A[2][2] as 100 here
    A(2, 2) = 100;

    for (int i = 0; i < 5; i++) {
        for (int j = 0; j < 6; j++)
            // It's same as  A[i][j] 
            std::cout << A(i, j) << " ";

        std::endl;
    } 
}

Output

0 1 2 3 4 5
6 7 8 9 10 11
12 100 14 15 16 17
18 19 20 21 22 23
24 25 26 27 28 29

Operations with Arithmetic Operations

Matrix Multiplication

Useful Functions

The usage of Vector

Algorithms for Linear Algebra

- Decompositions
- Algorthms