Matrix Template Library Help

王朝other·作者佚名  2006-01-31
窄屏简体版  字體: |||超大  

部分函数功能说明

// element access functions

int GetRowSize()const

int GetColSize()const

T GetValue(const int& row,const int& col)const

const vector<T> GetRowVector(const int& row)const

const vector<T> GetColVector(const int& col)const

const Matrix<T> GetRow(const int& row)const

const Matrix<T> GetCol(const int& col)const

// modify

void Resize(const int& row,const int& col,T value=T(0));

void SetValue(const int& row,const int& col,T value = T(0));

void AddRow(T value = T(0));

void AddCol(T value = T(0));

void DeleteRow(const int& row);

void DeleteCol(const int& col);

void InsertRow(const int& row,T value = T(0));

void InsertCol(const int& col,T value = T(0));

void SetRowVector(const int& row,const vector<T>& vec = vector<T>(0));

void SetColVector(const int& col,const vector<T>& vec = vector<T>(0));

void SwapRow(const int& row1,const int& row2);

void SwapCol(const int& col1,const int& col2);

【 这些函数不用介绍了,功能根据函数顾名思义。】

// special functions

Matrix<T> Turn(); //求转置矩阵

Matrix<T> Inverse(); //求逆矩阵(必须是方阵,并且可逆,否则抛出exception)

Matrix<T> Unit(const int& row); //单位矩阵(把矩阵重置为给定大小的单位阵)

Matrix<T> Diag(); //求对角阵(返回对角阵元素组成的行矩阵)

T Det(); //求矩阵的行列式的值(必须是方阵,否则抛出exception)

T Trace(); //求方阵的迹(必须是方阵,否则抛出exception)

T Norm(const int& p=2); // 求矩阵的范数(默认为求2范数。注意:只有folat,double,long double矩阵可以调用该函数)

T CondNumber(); //求矩阵的条件数

T Radius();// spectral radius //求矩阵的半径

int Rank(); //求矩阵的秩

Matrix<T> GetAij(const int& row,const int& col); //取得矩阵的子矩阵(大的截取,小的补零)

// transform

CMatrix< complex<double> > ToCDouble(); //将矩阵转换为double型的复数矩阵,以便于作矩阵间的运算

//实数矩阵特有函数

RMatrix<T> Jacobi(RMatrix<T>& value=RMatrix<T>()); //JACOBI迭代法求实数矩阵的特征值,特征解

RMatrix<double> ToDouble(); //转换为double型矩阵

// 复数阵特有函数

RMatrix<T> Real(); // 取得实部矩阵

RMatrix<T> Imag(); // 取得虚数矩阵

【下面给出一个应用此矩阵库的小程序,示意主要函数的用法】

#include <iostream>

#include <stdlib.h>

#include "matrix6.hpp"

using namespace std;

using namespace soubam;

int main(int argc, char *argv[])

{

try

{

complex< double > temp(3,4);

RMatrix< int > R1( 4, 3, 1), R2(3, 5, 2);

RMatrix< double > R3( 4, 4 ), R4(4, 3, 0.1);

CMatrix< int > C1( 4, 3,1), C2(3, 5, 2);

CMatrix< double > C3( 5, 6, 2.3),C4(6, 7, 0.3);

R1[0][0] = 3;

R1[0][1] = 5;

R1[0][2] = 4;

cout<<"R1="<<endl;

cout<<R1<<endl;

R3.SetValue(0,1,1);

R3.SetValue(1,1,2);

R3.SetValue(2,1,3);

cout<<"R3="<<endl;

cout<<R3<<endl;

cout<<"R4="<<endl;

cout<<R4<<endl;

cout<<"R3*R4="<<endl;

cout<<R3*R4<<endl;

cout<<"rank(R1)= "<<R1.Rank()<<endl;

R2.Det();

system("PAUSE");

return 0;

}

catch(OutOfRange e)

{

cout<<e.GetError()<<endl;

cout<<"row= "<<e.InvalidRow()<<endl;

cout<<"col= "<<e.InvalidCol()<<endl;

}

catch(MisMatch e)

{

cout<<e.GetError()<<endl;

}

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航