1 2 /* 3 * Matrix - Implements a matrix 4 * Copyright (c) 2003-2006 by Mattias Hultgren <mattias_hultgren@tele2.se> 5 * 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation; version 2 of the License. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public 17 * License along with this program; if not, write to the Free Software 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 */ 20 21 22 #ifndef MATRIX_H_ 23 #define MATRIX_H_ 24 25 #include "vartypes.h" 26 #include "integer.h" 27 #include "real.h" 28 #include "complex.h" 29 #include "utf8_string.h" 30 31 32 33 #define MATRIX_H_VERSION "v4" 34 #define MATRIX_H_DATE "2005-10 - 2006-08" 35 36 37 38 class Matrix 39 { 40 private: 41 uint32 width, height, next; 42 43 Complex *data; 44 45 public: 46 Matrix(); 47 Matrix(const Matrix &src) throw(error_obj); 48 ~Matrix(); 49 50 void operator=(const Matrix &src) throw(error_obj); 51 52 bool operator==(const Matrix &matr) const; 53 inline bool operator!=(const Matrix &matr) const { return !(this->operator==(matr)); } 54 55 // sets the size of the Matrix 56 void set_size(uint32 newwidth, uint32 newheight) throw(error_obj); 57 get_width(void)58 inline uint32 get_width(void) const { return width; } get_height(void)59 inline uint32 get_height(void) const { return height; } 60 61 // if col,row is outside the Matrix then nothing happens 62 void set_complex(uint32 col,uint32 row,const Complex &value) throw(error_obj); 63 64 // if width or height is zero nothing happens 65 // data[next++] = value; if( next >= width*height ) next = 0; // this isn't exactly but almost as it is in the code 66 void set_next( const Complex &value ) throw(error_obj); set_next_index(uint32 new_next)67 inline void set_next_index( uint32 new_next ) { next = new_next; } 68 69 // if col,row is outside the Matrix then 0+i*0 is returned 70 Complex get_complex(uint32 col,uint32 row) const throw(error_obj); 71 72 Complex det(void) const throw(error_obj); 73 74 void trans() throw(error_obj); 75 76 void fill(const Complex &val) throw(error_obj); 77 78 void identity(void) throw(error_obj); 79 80 void adjoint(void) throw(error_obj); 81 82 void inverse(void) throw(error_obj); 83 84 // swaps the two rows with each other...if the Matrix doesn't have that many rows nothing happens 85 void row_swap(uint32 row1,uint32 row2) throw(error_obj); 86 87 // multiplies a row with val...if the Matrix doesn't have that many rows nothing happens 88 void row_mul(uint32 row,const Complex &val) throw(error_obj); 89 90 // temporary multiplies src_row with val and add it with dest_row...if any of src_row & dest_row 91 // is too high for the Matrix nothing happens 92 void row_mul_add(uint32 src_row,const Complex &val,uint32 dest_row) throw(error_obj); 93 94 // this function replaces one row with one row from *src 95 // if any of src_row & dest_row is too high for the Matrix's nothing happens 96 void replace_row(uint32 dest_row, const Matrix *src, uint32 src_row) throw(error_obj); 97 98 // calculates dest = src1 + src2 99 friend void matrix_add(Matrix *dest,const Matrix *src1,const Matrix *src2) throw(error_obj); 100 101 // calculates dest = src1 - src2 102 friend void matrix_sub(Matrix *dest,const Matrix *src1,const Matrix *src2) throw(error_obj); 103 104 // calculates this *= val 105 void mul( const Complex &val ) throw(error_obj); 106 107 // calculates dest = src1 * src2 108 friend void matrix_mul(Matrix *dest,const Matrix *src1,const Matrix *src2) throw(error_obj); 109 110 // calculates dest = src ^ power 111 friend void matrix_pow( Matrix *dest, const Matrix *src, Integer power ) throw(error_obj); 112 113 void append_to_string( utf8_string &str, const Format &fmt, bool row_break=false ) const 114 throw(error_obj); 115 }; 116 117 118 119 #endif // MATRIX_H_ 120