Continuum Membrane 719025a62b1e384a6ff80e2f2a223ef4012153dc
Loading...
Searching...
No Matches
Linear_algebra.hpp
Go to the documentation of this file.
1
39#pragma once
40
41#include <vector>
42#include <iostream> //for bit push << overriding
43
44#include <gsl/gsl_matrix.h>
45#include <gsl/gsl_blas.h>
46#include <gsl/gsl_linalg.h>
47
64class Matrix
65{
66public:
67 gsl_matrix *mat;
68
78 Matrix(const int &nrow, const int &ncol, const bool &setToZero);
79
80
81
87
88
97 Matrix(const int &nrow);
98
108 Matrix(const int &nrow, const int &ncol);
109
118 Matrix(const Matrix &mat_src);
119
124 Matrix(const std::vector<std::vector<double>> &vec);
125
132 Matrix& operator=(const Matrix &mat_src);
133
145
150 void free();
151
156 int nrow() const;
157
162 int ncol() const;
163
168 double get(const int &i, const int &j) const;
169
174 double operator()(const int &i, const int &j) const;
175
180 void set(const int &i, const int &j, const double &v);
181
186 void set_all(const double &v);
187
195 void transpose();
196
204
211 Matrix get_row(const int &irow) const;
212
219 Matrix get_col(const int &icol) const;
220
227 void set_row_from_col(const int &destRow, const Matrix &srcMat, const int &srcCol);
228
235
244 void get_inverted(Matrix &matInverted);
245
250 double calculate_norm() const;
251
256 double calculate_quad() const;
257
258};
259
269Matrix mat_calloc(const int &nrow, const int &ncol);
270
282std::ostream &operator<<(std::ostream &stream, const Matrix &matrix);
283
296
305Matrix operator+(const Matrix &m1, const Matrix &m2);
306
319
328Matrix operator-(const Matrix &m1, const Matrix &m2);
329
339Matrix &operator*=(Matrix &mat, const double &scalar);
340
350Matrix operator*(const Matrix &matrix, const double &scalar);
351Matrix operator*(const double &scalar, const Matrix &matrix);
353
366
380Matrix operator*(const Matrix &m1, const Matrix &m2);
381Matrix dot(const Matrix &m1, const Matrix &m2);
383
393Matrix &operator/=(Matrix &mat, const double &scalar);
394
403Matrix operator/(Matrix matrix, const double &scalar);
404
412double dot_col(const Matrix &m1, const Matrix &m2);
413
421double dot_row(const Matrix &m1, const Matrix &m2);
422
430Matrix cross_col(const Matrix &m1, const Matrix &m2);
431
440Matrix cross_row(const Matrix &m1, const Matrix &m2);
441
458void negative(const Matrix &m1, Matrix &m_neg);
459
472
489void get_unit_vector(const Matrix &m1, Matrix &m_unit);
490
505void cross(const Matrix &m1, const Matrix &m2, Matrix &temp);
506
522void addition(const Matrix &m1, const Matrix &m2, Matrix &tmp);
523
539void subtraction(const Matrix &m1, const Matrix &m2, Matrix &tmp);
540
555void multiplication(const Matrix &m1, const Matrix &m2, Matrix &tmp);
556
571void const_multiplication(const Matrix &m1, const double num, Matrix &tmp);
572
587void const_division(const Matrix &m1, const double num, Matrix &tmp);
588
620void colvec_matrix_multiplication(const Matrix &v1, const Matrix &m1, Matrix &tmp);
621
641Matrix kron(const Matrix& v1, const Matrix& v2);
642
660Matrix kron(const Matrix &v1, const Matrix &v2, Matrix &m_result);
661
670void assign_rowVec_to_colVec(const Matrix &srcRowVec, Matrix &destColVec);
671
687 const Matrix &b,
688 const Matrix &c,
689 const Matrix &d,
690 Matrix &tmp_f,
691 Matrix &tmp_l,
692 Matrix &v_result);
double dot_row(const Matrix &m1, const Matrix &m2)
This implementation takes two row vectors as arguments and returns their dot product as double.
void subtraction(const Matrix &m1, const Matrix &m2, Matrix &tmp)
Compute the element-wise subtraction of two matrices and store the result in a third matrix.
double dot_col(const Matrix &m1, const Matrix &m2)
This implementation takes two column vectors as arguments and returns their dot product as double.
void addition(const Matrix &m1, const Matrix &m2, Matrix &tmp)
Compute the element-wise addition of two matrices and store the result in a third matrix.
Matrix & operator-=(Matrix &m1, const Matrix &m2)
This implementation takes two gsl_matrix pointers as arguments and subtract the elements of the secon...
Matrix operator/(Matrix matrix, const double &scalar)
This operator takes a double scalar and a matrix as its operands. It returns a new gsl_matrix* that i...
Matrix & operator+=(Matrix &m1, const Matrix &m2)
This implementation takes two gsl_matrix pointers as arguments and adds the elements of the second ma...
void a_cross_b_plus_c_cross_d(const Matrix &a, const Matrix &b, const Matrix &c, const Matrix &d, Matrix &tmp_f, Matrix &tmp_l, Matrix &v_result)
std::ostream & operator<<(std::ostream &stream, const Matrix &matrix)
Bit push all element of a matrix in the format of:
Matrix & operator*=(Matrix &mat, const double &scalar)
This implementation uses the gsl_matrix_scale function to scale each element in the matrix by the sca...
Matrix kron(const Matrix &v1, const Matrix &v2)
the Kronecker product between two column matrices and returns the result in an output matrix....
Matrix & operator/=(Matrix &mat, const double &scalar)
This implementation uses the gsl_matrix_scale function to scale each element in the matrix by 1/the s...
Matrix operator-(const Matrix &m1, const Matrix &m2)
This implementation checks that the matrices have the same dimensions and allocates memory for the re...
void get_unit_vector(Matrix &m)
Get the unit vector in the direction of m which is assumed to be a (3, 1) Matrix and overwrites the r...
void colvec_matrix_multiplication(const Matrix &v1, const Matrix &m1, Matrix &tmp)
Multiply a row vector by a matrix and store the result in a row vector.
Matrix cross_col(const Matrix &m1, const Matrix &m2)
This implementation takes two column vectors as arguments and returns their cross product as a new co...
void multiplication(const Matrix &m1, const Matrix &m2, Matrix &tmp)
Multiply a matrix by a constant and store the result in a second matrix.
Matrix cross_row(const Matrix &m1, const Matrix &m2)
This implementation takes two row vectors as arguments and returns their cross product as a new row v...
void const_division(const Matrix &m1, const double num, Matrix &tmp)
Divide a matrix by a constant and store the result in a second matrix.
Matrix operator+(const Matrix &m1, const Matrix &m2)
This implementation checks that the matrices have the same dimensions and allocates memory for the re...
void cross(const Matrix &m1, const Matrix &m2, Matrix &temp)
Compute the cross product of two 3D vectors represented as 3x1 matrices.
Matrix operator*(const Matrix &matrix, const double &scalar)
This operator takes a double scalar and a matrix as its operands. It returns a new gsl_matrix* that i...
void assign_rowVec_to_colVec(const Matrix &srcRowVec, Matrix &destColVec)
void negative(const Matrix &m1, Matrix &m_neg)
Computes the negative of a given matrix.
void const_multiplication(const Matrix &m1, const double num, Matrix &tmp)
Multiply a matrix by a constant and store the result in a second matrix.
Matrix dot(const Matrix &m1, const Matrix &m2)
Matrix mat_calloc(const int &nrow, const int &ncol)
This function allocates a new Matrix object with the specified number of rows and columns,...
Matrix used in continuum membrane model.
Definition Linear_algebra.hpp:65
double calculate_norm() const
Calculates the Euclidean norm of the member matrix mat.
void get_inverted(Matrix &matInverted)
This function uses cholesky decomposition to solve for the inverse of the input square matrix....
double get(const int &i, const int &j) const
Get element value at i,j.
double calculate_quad() const
Calculates the Euclidean quadrance of the member matrix mat.
void set(const int &i, const int &j, const double &v)
Set element value at i,j to v.
Matrix()
Default constructor.
Matrix & operator=(const Matrix &mat_src)
Assignment operator.
double operator()(const int &i, const int &j) const
Get element value at i,j.
void set_row_from_col(const int &destRow, const Matrix &srcMat, const int &srcCol)
Set the row vector from col vector.
Matrix(const int &nrow, const int &ncol, const bool &setToZero)
Construct a new Matrix object and initialize the members to zeros. The setToZero variable is a place ...
gsl_matrix * mat
Definition Linear_algebra.hpp:67
void free()
Free memory allocation for a Matrix object.
Matrix(const Matrix &mat_src)
Copy constructor for creating a deep copy of a Matrix object.
void set_all(const double &v)
Set all elements to v.
Matrix(const int &nrow, const int &ncol)
Constructor for creating a Matrix with a specified number of rows and columns.
Matrix get_row(const int &irow) const
Get the row vector in the format of Matrix(1, N)
~Matrix()
Destructor for the Matrix class that frees the memory allocated by the mat member.
Matrix get_transposed() const
Get the tranposed matrix.
void transpose()
Transpose the matrix. This overwrites the original matrix.
void set_identity()
Set the matrix to identity matrix.
int ncol() const
get number of columns
Matrix get_col(const int &icol) const
Get the col vector in the format of Matrix(N, 1)
Matrix(const int &nrow)
Constructor for creating a Matrix with a specified number of rows and one column.
Matrix(const std::vector< std::vector< double > > &vec)
Intialize a matrix with a 2d vector.
int nrow() const
get number of rows