angchen

angchen

 

Matrix 头文件

#ifndef MATRIX_H
#define MATRIX_H

#include
<iostream>
#include
<cstdlib>

using namespace std;

class Matrix;
ostream
& operator <<(ostream& output, const Matrix& m);
istream
& operator >>(istream& input , Matrix& m);
const bool operator ==(const Matrix& M1, const Matrix& M2);

const Matrix operator +(const Matrix& M1, const Matrix& M2);
const Matrix operator -(const Matrix& M1, const Matrix& M2);
Matrix 
operator *(const Matrix& M1, const Matrix& M2);
Matrix 
operator *(const double k, const Matrix& M1);
const Matrix operator ~(const Matrix& M1);//the transpose of the matrix
Matrix operator /(const Matrix& M1, double k);

class Matrix
{
public:
    Matrix();
    Matrix(
int n);
    Matrix(
int row, int col);
    Matrix(
int row, int col, double *a);
    Matrix(
const Matrix& other);

    
~Matrix();

    
int GetRow() const;
    
int GetCol() const;
    
double GetData(int i, int j) const;

    Matrix
& operator =(const Matrix& other);
    friend ostream
& operator <<(ostream& output, const Matrix& m);
    friend istream
& operator >>(istream& input , Matrix& m);
    friend 
const bool operator ==(const Matrix& M1, const Matrix& M2);

    friend 
const Matrix operator +(const Matrix& M1, const Matrix& M2);
    friend 
const Matrix operator -(const Matrix& M1, const Matrix& M2);
    friend Matrix 
operator *(const Matrix& M1, const Matrix& M2);
    friend Matrix 
operator *(const double k, const Matrix& M2);
    friend 
const Matrix operator ~(const Matrix& M1);//
    friend Matrix operator /(const Matrix& M1, double k);//overload the / for matrix's divide.
    
//i.e.each component of matrix divide by k.


    
double& operator ()(int i, int j);//we set ()quote in ordor to use () as a left-hand value.
    
//return a vector which from M1(rcBegin:rcEnd, rc2) or M1(rc1, rcBegin:rcEnd)
    Matrix& GetColVectorOfMatrix(int c, int rBegin, const Matrix& M1, Matrix& v);//int rBegin, int rEnd, 
    Matrix& Get2DataOfCol(int c, int r1, int r2, const Matrix& M1, Matrix& v);
    
//get two entries of a certain column i.e. (r1,c),(r2,c).
    Matrix& GetSubMatrix(int r1, int r2, int c1, int c2, Matrix& M1, Matrix& m);
    Matrix
& SetSubMatrix(int r1, int r2, int c1, int c2, Matrix& M1, Matrix& m);

    Matrix
& SwapRow(int i, int j, Matrix& M1);//exchange the two rows which are select.
    Matrix& SwapCol(int i, int j, Matrix& M1);//exchange the two columns which are select.
    int* MaxRowCol(int RCn[2], const Matrix& M1, const int flag);//RCn for the Row and column number.
    
//flag=1 representive for do not consider the diagonal entries.

    
double Norm1(const Matrix& M1);//solve the norm1.
    double NormInfinite(const Matrix& M1);//solve the infinite-norm 
    double Norm2Frobenius(const Matrix& M1);//solve the Frobenius-norm for matrix and 2-norm 
                                                
//for vector.
    double ConditionNum1(const Matrix& M1);//solve the condition of matrix with norm1.
    double ConditionNumInf(const Matrix& M1);//solve the condition of matrix with infinite-norm.
    double DotVector(const Matrix& M1, const Matrix& M2);

    Matrix
& inverse(Matrix& M1);//by the Gauss-Jordon Emlimination Method with the all-big-povit.
    Matrix& LU(Matrix& M1);//by the Gauss Emlimination Method.
    Matrix HouseholderTranf(Matrix& x);//return v ,and the householder matrix equal to I-2*w*w' 
    
//which w=v/norm2(v).
    Matrix GivensTranf(Matrix& v);//return a vector which c=vr(0,0) and s=vr(1,0).
    Matrix QRHouseholder(Matrix& M1);
    Matrix
* QRHouseholderReturnQR(Matrix& M1, Matrix *qr);//return Q and R.

    
double PowerMethod(Matrix& M1, Matrix& x0, const double tol);//power method return a biggest eigenvalue
    double InversePower(Matrix& M1, Matrix& x0, const double tol);//InversePower method return a smallest eigenvalue
    Matrix JacobiSolInv(Matrix& M1, const double tol);//return all of the eigenvalue of matrix.
                                
//the matrix need to be square and symmetry.

private:
    
int row;
    
int col;
    
double *M;

}
;
#endif

posted on 2009-04-14 12:19 陈安 阅读(725) 评论(0)  编辑 收藏 引用


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


导航

统计

常用链接

留言簿(1)

随笔档案

搜索

最新评论

阅读排行榜

评论排行榜