如果您无法下载资料,请参考说明:
1、部分资料下载需要金币,请确保您的账户上有足够的金币
2、已购买过的文档,再次下载不重复扣费
3、资料包下载后请先用软件解压,在使用对应软件打开
矩阵计算程序(完整版)实用资料(可以直接使用,可编辑完整版实用资料,欢迎下载)#ifndef_MATRIX_H#define_MATRIX_HclassMatrix{private:introw;//矩阵的行数intcol;//矩阵的列数intn;//矩阵元素个数double*mtx;//动态分配用来存放数组的空间public:Matrix(introw=1,intcol=1);//带默认参数的构造函数Matrix(introw,intcol,doublemtx[]);//用数组创建一个矩阵Matrix(constMatrix&obj);//copy构造函数~Matrix(){delete[]this->mtx;}voidprint()const;//格式化输出矩阵intgetRow()const{returnthis->row;}//访问矩阵行数intgetCol()const{returnthis->col;}//访问矩阵列数intgetN()const{returnthis->n;}//访问矩阵元素个数double*getMtx()const{returnthis->mtx;}//获取该矩阵的数组//用下标访问矩阵元素doubleget(constinti,constintj)const;//用下标修改矩阵元素值voidset(constinti,constintj,constdoublee);//重载了一些常用操作符,包括+,-,x,=,负号,正号,//A=BMatrix&operator=(constMatrix&obj);//+AMatrixoperator+()const{return*this;}//-AMatrixoperator-()const;//A+BfriendMatrixoperator+(constMatrix&A,constMatrix&B);//A-BfriendMatrixoperator-(constMatrix&A,constMatrix&B);//A*B两矩阵相乘friendMatrixoperator*(constMatrix&A,constMatrix&B);//a*B实数与矩阵相乘friendMatrixoperator*(constdouble&a,constMatrix&B);//A的转置friendMatrixtrv(constMatrix&A);//A的行列式值,采用列主元消去法//求行列式须将矩阵化为三角阵,此处为了防止修改原矩阵,采用传值调用frienddoubledet(MatrixA);//A的逆矩阵,采用高斯-若当列主元消去法friendMatrixinv(MatrixA);};#endif实现#include<iostream.h>#include<math.h>#include<stdlib.h>#include<iomanip.h>#include"matrix.h"//带默认参数值的构造函数//构造一个row行col列的零矩阵Matrix::Matrix(introw,intcol){this->row=row;this->col=col;this->n=row*col;this->mtx=newdouble[n];for(inti=0;i<n;i++)this->mtx[i]=0.0;}//用一个数组初始化矩阵Matrix::Matrix(introw,intcol,doublemtx[]){this->row=row;this->col=col;this->n=row*col;this->mtx=newdouble[n];for(inti=0;i<n;i++)this->mtx[i]=mtx[i];}//拷贝构造函数,因为成员变量含有动态空间,防止传递参数//等操作发生错误Matrix::Matrix(constMatrix&obj){this->row=obj.getRow();this->col=obj.getCol();this->n=obj.getN();this->mtx=newdouble[n];for(inti=0;i<n;i++)this->mtx[i]=obj.getMtx()[i];}//格式化输出矩阵所有元素voidMatrix::print()const{for(inti=0;i<this->row;i++){for(intj=0;j<this->col;j++)if(fabs(this->get(i,j))<=1.0e-10)cout<<setiosflags(ios::left)<<setw(12)<<0.0<<'';elsecout<<setiosflags(ios::left)<<setw(12)<<this->