Matrix 头文件

ContractedBlock.gif ExpandedBlockStart.gif Code
 1#ifndef MATRIX_H
 2#define MATRIX_H
 3
 4#include<iostream>
 5#include<cstdlib>
 6
 7using namespace std;
 8
 9class Matrix;
10ostream& operator <<(ostream& output, const Matrix& m);
11istream& operator >>(istream& input , Matrix& m);
12const bool operator ==(const Matrix& M1, const Matrix& M2);
13
14const Matrix operator +(const Matrix& M1, const Matrix& M2);
15const Matrix operator -(const Matrix& M1, const Matrix& M2);
16Matrix operator *(const Matrix& M1, const Matrix& M2);
17Matrix operator *(const double k, const Matrix& M1);
18const Matrix operator ~(const Matrix& M1);//the transpose of the matrix
19Matrix operator /(const Matrix& M1, double k);
20
21class Matrix
22ExpandedBlockStart.gifContractedBlock.gif{
23public:
24    Matrix();
25    Matrix(int n);
26    Matrix(int row, int col);
27    Matrix(int row, int col, double *a);
28    Matrix(const Matrix& other);
29
30    ~Matrix();
31
32    int GetRow() const;
33    int GetCol() const;
34    double GetData(int i, int j) const;
35
36    Matrix& operator =(const Matrix& other);
37    friend ostream& operator <<(ostream& output, const Matrix& m);
38    friend istream& operator >>(istream& input , Matrix& m);
39    friend const bool operator ==(const Matrix& M1, const Matrix& M2);
40
41    friend const Matrix operator +(const Matrix& M1, const Matrix& M2);
42    friend const Matrix operator -(const Matrix& M1, const Matrix& M2);
43    friend Matrix operator *(const Matrix& M1, const Matrix& M2);
44    friend Matrix operator *(const double k, const Matrix& M2);
45    friend const Matrix operator ~(const Matrix& M1);//
46    friend Matrix operator /(const Matrix& M1, double k);//overload the / for matrix's divide.
47    //i.e.each component of matrix divide by k.
48
49
50    double& operator ()(int i, int j);//we set ()quote in ordor to use () as a left-hand value.
51    //return a vector which from M1(rcBegin:rcEnd, rc2) or M1(rc1, rcBegin:rcEnd)
52    Matrix& GetColVectorOfMatrix(int c, int rBegin, const Matrix& M1, Matrix& v);//int rBegin, int rEnd, 
53    Matrix& Get2DataOfCol(int c, int r1, int r2, const Matrix& M1, Matrix& v);
54    //get two entries of a certain column i.e. (r1,c),(r2,c).
55    Matrix& GetSubMatrix(int r1, int r2, int c1, int c2, Matrix& M1, Matrix& m);
56    Matrix& SetSubMatrix(int r1, int r2, int c1, int c2, Matrix& M1, Matrix& m);
57
58    Matrix& SwapRow(int i, int j, Matrix& M1);//exchange the two rows which are select.
59    Matrix& SwapCol(int i, int j, Matrix& M1);//exchange the two columns which are select.
60    int* MaxRowCol(int RCn[2], const Matrix& M1, const int flag);//RCn for the Row and column number.
61    //flag=1 representive for do not consider the diagonal entries.
62
63    double Norm1(const Matrix& M1);//solve the norm1.
64    double NormInfinite(const Matrix& M1);//solve the infinite-norm 
65    double Norm2Frobenius(const Matrix& M1);//solve the Frobenius-norm for matrix and 2-norm 
66                                                //for vector.
67    double ConditionNum1(const Matrix& M1);//solve the condition of matrix with norm1.
68    double ConditionNumInf(const Matrix& M1);//solve the condition of matrix with infinite-norm.
69    double DotVector(const Matrix& M1, const Matrix& M2);
70
71    Matrix& inverse(Matrix& M1);//by the Gauss-Jordon Emlimination Method with the all-big-povit.
72    Matrix& LU(Matrix& M1);//by the Gauss Emlimination Method.
73    Matrix HouseholderTranf(Matrix& x);//return v ,and the householder matrix equal to I-2*w*w' 
74    //which w=v/norm2(v).
75    Matrix GivensTranf(Matrix& v);//return a vector which c=vr(0,0) and s=vr(1,0).
76    Matrix QRHouseholder(Matrix& M1);
77    Matrix* QRHouseholderReturnQR(Matrix& M1, Matrix *qr);//return Q and R.
78
79    double PowerMethod(Matrix& M1, Matrix& x0, const double tol);//power method return a biggest eigenvalue
80    double InversePower(Matrix& M1, Matrix& x0, const double tol);//InversePower method return a smallest eigenvalue
81    Matrix JacobiSolInv(Matrix& M1, const double tol);//return all of the eigenvalue of matrix.
82                                //the matrix need to be square and symmetry.
83
84private:
85    int row;
86    int col;
87    double *M;
88
89}
;
90#endif

 

上面是近期写的一个矩阵类。

实现的功能主要是先编写最基本的运算,然后在增加新算法的时候才对其基本功能进行增加。

转载于:https://www.cnblogs.com/angchen/archive/2009/04/14/1435846.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值