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
陈安
阅读(763)
评论(0)
编辑
收藏
引用
只有注册用户
登录
后才能发表评论。
【推荐】100%开源!大型工业跨平台软件C++源码提供,建模,组态!
网站导航:
博客园
IT新闻
BlogJava
知识库
博问
管理
导航
C++博客
首页
新随笔
联系
聚合
管理
统计
随笔 - 2
文章 - 0
评论 - 1
引用 - 0
常用链接
我的随笔
我的评论
我参与的随笔
留言簿
(1)
给我留言
查看公开留言
查看私人留言
随笔档案
2009年4月 (2)
搜索
最新评论
1. re: 解线性方程组的头文件
只是一些较简单的算法实现。还得继续完善。
--陈安
阅读排行榜
1. Matrix 头文件(763)
2. 解线性方程组的头文件(307)
评论排行榜
1. 解线性方程组的头文件(1)
2. Matrix 头文件(0)
Powered by:
C++博客
Copyright © 陈安