?? 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 + -