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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
SparseMatrix
operator*(const double scalar, SparseMatrix &m){
SparseMatrix ret(m.numRows());
for(int k = 0; k < ret.numRows(); k++) {
if(k < (ret.numRows()-1)){
ret(k,k) = scalar*m(k,k);
ret(k,k+1) = scalar*m(k,k+1);
ret(k+1,k) = scalar*m(k+1,k);
}
else{
ret(k,k) = scalar*m(k,k);
}
}
return ret;
}
SparseMatrix
operator+(SparseMatrix &m, SparseMatrix &A){
SparseMatrix ret(m.numRows());
for(int k = 0; k < ret.numRows(); k++) {
if(k < (ret.numRows()-1)){
ret(k,k) = m(k,k)+A(k,k);
ret(k,k+1) = m(k,k+1)+A(k,k+1);
ret(k+1,k) = m(k+1,k)+A(k+1,k);
}
else{
ret(k,k) = m(k,k)+A(k,k);
}
}
return ret;
}
SparseMatrix
operator-(SparseMatrix &m, SparseMatrix &A){
SparseMatrix ret(m.numRows());
for(int k = 0; k < ret.numRows(); k++) {
if(k < (ret.numRows()-1)){
ret(k,k) = m(k,k)-A(k,k);
ret(k,k+1) = m(k,k+1)-A(k,k+1);
ret(k+1,k) = m(k+1,k)-A(k+1,k);
}
else{
ret(k,k) = m(k,k)-A(k,k);
}
}
return ret;
}
|