📄 matrix.hpp
字号:
// Matrix.hpp// A matrix definition for real or complex matrices// a nonsquare generalization of class in Computers In Physics Jan/Feb 1990// NOTE: scalar assignment of a Matrix creates a diagonal matrix// with the given scalar value. THIS IS DIFFERENT from scalar// assignment to a Basic2DArray (V1.3) where it SETS ALL THE ELEMENTS// to that value. Be careful with polymorphism here!// (c) Copyright 1995, Everett F. Carter Jr.// Permission is granted by the author to use// this software for any application provided this// copyright notice is preserved.// rcsid: $Id$ @(#)matrix.hpp 1.7 12:25:58 4/24/95 EFC#ifndef MATRIX_H_#define MATRIX_H_ 1.7#include <stdio.h>#include <iostream.h>#include <math.h>#ifndef INCLUDE_VECTOR#define INCLUDE_VECTOR#endif#include <barray2d.hpp>#ifdef INCLUDE_VECTOR#include <vector.hpp>#endif#ifdef USE_MATRIX_ROWclass MatrixRow{ private: int index; scalar_type **m; public: MatrixRow() {} MatrixRow(const int i, scalar_type** mi) : index(i), m(mi) {} MatrixRow(const MatrixRow& rw) : index(rw.index), m(rw.m) {} ~MatrixRow() {} void assoc(const int i, scalar_type** mi) { index = i; m = mi; } scalar_type& operator[](const int j) { return m[index][j]; } };#endifclass Matrix : public Basic2DArray{ protected:#ifdef USE_MATRIX_ROW MatrixRow row;#endif public: Matrix(const int r,const int c) : Basic2DArray(r,c) {} Matrix() {} Matrix(const Matrix& m) : Basic2DArray(m) {} // initialization ~Matrix() {} // destructor Matrix& operator=(const Matrix&); // assignment // scalar assignment scalar_type operator=(const scalar_type v) { reset(0.0); diag(v); return v; }#ifdef USE_MATRIX_ROW MatrixRow operator[](const int i) { row.assoc(i,m); return row; } MatrixRow operator[](const int i) const { row.assoc(i,m); return row; }#endif void diag(const scalar_type fv); // set diagonals friend Matrix operator+(const Matrix&,const Matrix&); // Mat+Mat friend Matrix operator-(const Matrix&,const Matrix&); // Mat-Mat friend Matrix operator*(const Matrix&,const Matrix&); // Mat*Mat friend Matrix operator*(const double&,const Matrix&); // double*Mat#ifdef COMPLEX friend Matrix operator*(const Complex&,const Matrix&); // Complex*Mat#endif#ifdef INCLUDE_VECTOR friend Vector operator*(const Matrix&,Vector&); // Mat*Vector#endif friend int operator==(const Matrix&,const Matrix&); // equality friend Matrix comm(const Matrix&,const Matrix&); // commutator friend Matrix herm(const Matrix&); // hermitean conj friend Matrix transpose(const Matrix&); // transpose friend scalar_type trace(const Matrix& ); // trace};#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -