Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
/ matrixop Public archive

A C++11 matrix algebra library. Project for the exam "Elementi di programmazione per la fisica" at Bachelor in Physics.

License

Notifications You must be signed in to change notification settings

JustWhit3/matrixop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

93 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A C++11 matrix algebra library. Project for the exam "Elementi di programmazione per la fisica" at Bachelor in Physics.

v2.0 license C++11
code size repo size total lines


Table of contents

Introduction

The purpose of this library is to perform a good part of the main useful mathematical operations between matrices. It runs only over squared matrices of the same order. A list of the features is shown here.

If you want to cite this repository, please use this template.

Output example:

Description of the repository

Repository diagram structure:

matrixop/
├── include/
│   ├── matrixop.h
├── src/
│   ├── matrixop.cpp
│   ├── main.cpp
│── img
│── README.md
│── CITATION.cff
│── License
│── .gitignore
├── makefile

Excluding this README.md file, the License file and the .gitignore file, the repository contains two directories:

  • include: which contains the class and functions declaration file matrixop.h.
  • src: which contains two .cpp files:
    • matrixop.cpp: which is the manipulator definition file.
    • main.cpp: which shows you an example of the manipulator utility.

There is also a makefile for code compilation.

Run the code

Download

To download the manipulator you can proceed in two independent ways.

Download the whole repository

First of all, you need to download the code: go to the main page of the repository and click on the upper right green button called Code. Than click on Download ZIP and wait the download to be completed.

Then open a fresh shell and move the downloaded zipped file to your home directory (or to any other place you prefer):

mv Downloads/matrixop-master.zip $HOME

Where Downloads have to be replaced with the right name (and maybe the right path) of your downloads directory.

Now you have to enter your home folder (unless you were already in it, in this case skip this passage), extract the folder from the zipped file and renaming itself with its right repository name. Therefore lets type this commands one after the other:

cd $HOME
unzip matrixop-master.zip
mv matrixop-master matrixop

And that's all. You can enter the folder by simply typing:

cd matrixop

Download the latest release

Alternatively you can download the latest version of the repository from the Releases button on the right of the repository main page by clicking on the source code link. In this case the procedure is similar:

Open a fresh shell and move the downloaded zipped file to your home directory (or to any other place you prefer):

mv Downloads/matrixop-x.y.z.zip $HOME

Where x.y.z is the release tag and Downloads have to be replaced with the right name (and maybe the right path) of your downloads directory.

Now you have to enter your home folder (unless you were already in it, in this case skip this passage), extract the folder from the zipped file and renaming itself with its right repository name. Therefore lets type this commands one after the other:

cd $HOME
unzip matrixop-x.y.z.zip
mv matrixop-x.y.z matrixop

If you prefer to download the tar.gz format of the release you have to run the gunzip command followed by the tar -xvf command on the zipped release folder and than proceed with mv.

And that's all. You can enter the folder by simply typing:

cd matrixop

Compile and run

Now, let's suppose to continue from the previous step. For the compilation part I prepared a makefile, in order to simplify this procedure. So you have to run the makefile by typing:

make

An extra obj folder with object files and an executable called main are now created: you have simply to run this latter in order to run the entire example code:

./main

There is also an option to go back to the pre-compilation state of the code, to do this simply type this command:

make clean

How does matrixop work

Include the library

Once you have added the library to one of your project, you may want to be able to use it freely in your code. In order to let it works you have to include it at the beginning of a code in this way:

#include "path/to/matrixop/matrixop.h"

Where path/to/matrixop/ is the path to the directory in which you put the matrixop library. If you put the library in the same folder of the project you are working with you have simply to do:

#include "matrixop.h"

In this latter case you can omit the full path.

Remember to do this also in matrixop.cpp and in your makefile or maybe set this latter in order to avoid this path dependence.

Now you are able to access the class and al the functions of the library.

Class and functions

Functions:

  • template <class A> A MaxPtr (A *ptr, int a): template class useful to find maximum value of a pointer.

Class matrixop:

  • Constructors: default matrixop () {} and matrixop (int).
  • Destructor: ~Matrice ().
  • Methods:
    • inverse(): method useful to invert the matrix with the Gauss algorithm.
    • reset(): method useful to reset a matrix.
    • trace(): gives the trace of a matrix.
    • determinant(): gives the determinant of a matrix.
    • linear_system(): gives solutions of a matrix linear system with the Gauss method.
    • transpose(): gives the transpose of a matrix.
    • print_I(double **ptr): takes a matrix and prints it in a file.
    • print_data(double data): takes a number and prints it in a file.
    • print_sol(double *vet): takes a vector and prints it in a file.
    • rank(): gives the rank of a matrix.
    • matrix_norm(): gives the norm (norm-1, norm-inf, Frobenius norm) of a matrix.
    • zero(): method to set the "zero" of a matrix, in respect to the order of magnitude of each element.
  • Operators redefinitions:
    • +=: for the sum between each element of matrices.
    • -=: for the difference between each element of matrices.
    • *=: for the rows by columns product of matrices.
    • <<: for the output print of a matrix.

List of features

List of the documentations for each operation supported the by program:

  • Sum and difference between matrices: see here.

  • Rows by columns matrices product: see here.

  • Matrix inversion with Gaus algorithm: see here.

  • Matrix trace: see here.

  • Matrix determinant: see here.

  • Resolution of linear systems by the Gauss method: see here.

  • Matrix transpose: see here.

  • Matrix rank: see here.

  • Matrix norm: see here.

  • Matrix Frobenius norm: see here.

About

A C++11 matrix algebra library. Project for the exam "Elementi di programmazione per la fisica" at Bachelor in Physics.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published