Git Product home page Git Product logo

matrix_cpp's Introduction

Oxxxymiron Oxxxymiron - ГОРГОРОД
The One Album to Rule Them All

Matrix - linear algebra library for C++

This project is similar to the project on C (link) but with couple differences.
Here we have better user experience because of the Object-Orientation of C++.

Installation

macOS

git clone https://github.com/georghegel/matrix_cpp.git
cd matrix_cpp
make

For test:

make test

Linux

Similar to macOS:

git clone https://github.com/georghegel/matrix_cpp.git
cd matrix_cpp
make

For test:

not ready yet

How to use

Arithmetic operations

Addition/Subtraction

S21Matrix m1(3,3);
S21Matrix m2(3,3);

m1(0,0) = 1;
m1(0,1) = 2;
m1(0,2) = 3;
m1(1,0) = 4;
m1(1,1) = 5;
m1(1,2) = 6;
m1(2,0) = 7;
m1(2,1) = 8;
m1(2,2) = 9;

// let's say m2 fills in the same way
m1.SumMatrix(m2);

Let's print the result (it's located in m1):

m1.print();
//  2   4   6
//  8   10  12
//  14  16  18

Multiply by number

Element-wise multiplication by a given number:

S21Matrix m1(3,3); // just take the matrix from the previous example

double number = -3.0;
m1.MulNumber(number);

m1.print();
//  -3  -6  -9
//  -12 -15 -18
//  -21 -24 -27

Matrix multiplication

Here is the link how does it work:

S21Matrix m1(3,3); // as in the previous example
S21Matrix m2(3,3);

m2(0,0) = 0.7;
m2(0,1) = 11;
m2(0,2) = 0.3;
m2(1,0) = 11;
m2(1,1) = 2;
m2(1,2) = 1;
m2(2,0) = 0.5;
m2(2,1) = 3;
m2(2,2) = -1;

m1.MulMatrix(m2);

m1.print();

//  24.2    24    -0.7
//  60.8    72     0.2
//  97.4    120    1.1

Determinant

How to calculate determinant in Wiki:

S21Matrix m1(2,2);

m1(0,0) = 1;
m1(0,1) = 2;
m1(1,0) = 3;
m1(1,1) = 4;

double det = m1.Determinant();
std::cout << "Determinant is equal to " << det << std::endl;
//  Determinant is equal to -2

Inverse Matrix

About inverse matrix on Wiki:

S21Matrix m1(3,3);
S21Matrix inverse(3,3); // where will live our inverse matrix
m1(0,0) = 1;
m1(0,1) = 2;
m1(0,2) = 13;
m1(1,0) = 4;
m1(1,1) = 51;
m1(1,2) = 6;
m1(2,0) = 17;
m1(2,1) = 8;
m1(2,2) = 2;

inverse = m1.InverseMatrix();
inverse.print();

//  -54/10613   -100/10613    651/10613
//  -94/10613    219/10613    -46/10613
//  835/10613    -26/10613    -43/10613

Conjugate Matrix

S21Matrix m1(3,3);
S21Matrix res(3,3);
m1(0,0) = 1;
m1(0,1) = 2;
m1(0,2) = 3;
m1(1,0) = 0;
m1(1,1) = 4;
m1(1,2) = 2;
m1(2,0) = 5;
m1(2,1) = 2;
m1(2,2) = 1;

res = m1.CalcComplements();
res.print();

//   0   10  -20
//   4  -14    8
//  -8   -2    4

Some other useful functions:

Method signature Description
void Resize(int rows, int cols) resizes matrix to the given rows and columns
void print() prints matrix
S21Matrix transpose() transposes initial matrix and returns new, transposed one
bool EqMatrix(const S21Matrix& other) returns true, if matrices are equal. otherwise 0

matrix_cpp's People

Contributors

georghegel avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.