📄 mymatrix.h
字号:
#ifndef MYMATRIX_H
#define MYMATRIX_H
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
#define MAXSIZE 10
#define TIMES 5000
#define PI 3.1415926
class MyMatrix
{
private:
double matrix[MAXSIZE][MAXSIZE];
int row;
int col;
public:
MyMatrix(double matrix[][MAXSIZE]=NULL,int row=MAXSIZE,int col=MAXSIZE);
MyMatrix(MyMatrix &A);
void operator=(MyMatrix B);
MyMatrix friend operator*(MyMatrix A,MyMatrix B);
MyMatrix friend operator*(MyMatrix A,double coefficient);
void Display();
/*雅克比方法计算矩阵的特征值及特征向量,eigenvalue为特征向量矩阵*/
MyMatrix JacobiMethod(MyMatrix &eigenvalue);
/*获得绝对值最大的非对角元素的值及位置*/
double GetMaxAbsNondialogElement(int &r,int &c);
/*获得绝对值最大的元素的值*/
double GetMaxAbsElement();
/*矩阵转置*/
MyMatrix TransposeMatrix();
double GetElement(int row,int col);
void SwapColumn(int a,int b);
bool SetElement(int row,int col,double value);
/*计算行的平均值*/
double GetMeanOfRow(int row);
/*计算列的平均值*/
double GetMeanOfCol(int col);
int GetRow();
int GetCol();
/*对各分量进行标准化
Xi'=(Xi-mean(Xi))/sqrt(Lii*(n-1)) (i=1,2,3...n)
L为偏差平方和矩阵
Lii=(Xi-mean(Xi))*(Xi-mean(Xi))
标准化后的矩阵可用于在PCA中计算得分值
*/
MyMatrix StandarlizeVectors();
/*计算某行元素的标准差
计算公式SD=sqrt((Xi-mean(X)*(Xi-mean(X))/(n-1))
*/
double GetRowStandardDeviration(int row);
/*计算两行元素之间的协方差
计算公式Cov(X,Y)=(sigma((X-mean(X))*(Y-mean(Y)))/(n-1))
*/
double GetRowCovirance(int r1,int r2);
/*计算相关系数矩阵
两个变量的相关系数等于它们的协方差与各自标准偏差之比
计算相关阵时无需对样本进行标准化*/
MyMatrix GetCorelationMatrix();
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -