Skip to content

Commit

Permalink
Included a method to create a diagonal matrix with constant diagonal …
Browse files Browse the repository at this point in the history
…value
  • Loading branch information
philippedevloo committed Dec 13, 2021
1 parent 9276d61 commit 0d1e87f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Matrix/pzmatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,19 @@ void TPZMatrix<TVar>::Identity() {
}
}

template<class TVar>
void TPZMatrix<TVar>::Diagonal(TVar val) {

if ( Cols() != Rows() ) {
Error( "Diagonal (TPZMatrix<>*) <TPZMatrix<>must be square>" );
}
for ( int64_t row = 0; row < Rows(); row++) {
for ( int64_t col = 0; col < Cols(); col++ ) {
(row == col)? PutVal(row,col,val):PutVal(row,col,0.);
}
}
}


template<class TVar>
void TPZMatrix<TVar>::Input(std::istream& in )
Expand Down
2 changes: 2 additions & 0 deletions Matrix/pzmatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ class TPZMatrix: public TPZBaseMatrix

/** @brief Converts the matrix in an identity matrix*/
virtual void Identity();
/** @brief Converts the matrix in a diagonal matrix*/
virtual void Diagonal(TVar val);
/** @brief It makes *T the transpose of current matrix. */
virtual void Transpose(TPZMatrix<TVar>*const T) const;

Expand Down

0 comments on commit 0d1e87f

Please sign in to comment.