#pragma overce # include "dibimage.h" #include "exception.h" // matrix class - declaration
Class Matrix {private: // Matrix Width long width; // Matrix Height Long Height; Protected: // Matrix First Address Double * P; Public: Static Matrix One (long n); Void Info (); // Display Information Long getHeight (); long getWidth (); bool isvector (); // If it is false, that is a number double deter (); // seeking a row of determinant bool isptv (); // Is it matrix eigen (); // Sicular value Matrix Adjoint (); // accompanied by matrix matrix t (); // transfers Matrix INV (); // Multi-matrix Void Unity (); // Normalized Void Store (Const Char * filename); // Store the matrix to the file matrix bicubic (long n); // constructs the following similar matrix / * {2, 0.5, 0, 0, 0, 0}, {0.5, 2, 0.5, 0, 0, 0 }, {0, 0.5, 2, 0.5, 0, 0}, {0, 0, 0.5, 2, 0.5, 0}, {0,0,0,0.5,2,0.5,}, {0, 0, 0, 0, 0.5, 2,}}; * / Matrix Submatrix (long offset); // throw (Exception &); Matrix Submatrix (long x, long y, long widthoffset, long heightoffset); // Refer to a number of positions District // Matrix Submatrix (Double X, Double Y, Long Widthoffset, long Heightoffset); // Take a small number of position sub-area void test (); // Test function / ********** Overloaded section -OverLoaded Part **************** / Matrix Operator (Matrix &); Matrix Operator- (Matrix &); Matrix Operator * (Matrix &); Friend Matrix Oper Ator * (Double Alpha, Matrix &); // Real Number multiplied Matrix Operator * (double alpha); // matrix multiplying Matrix Operator / (Matrix &); // Real as a real number or matrix and Real numbers to remove Matrix Operator / (Double Sub); Matrix Operator = (Matrix &); Matrix Operator - = (Matrix &); Matrix Operator * = (Matrix &); // Matrix Multiply Matrix Operator * = (Double) Alpha); // matrix with real numbers Matrix & Operator = (Matrix &); // Assign Double * Operator [] (long Heightpos); // Used to implement [] [] Operation matrix element Friend Matrix SQRT (Matrix M ); // 开方 Friend Double Abs (Matrix &); // Take Absolute Value (Pan) Friend Double Sum (Matrix &); // Qi Friend Matrix Multiply (Matrix & M1, Matrix & M2); // Press Elements multiplied Friend Double Operator (Double DBL, Matrix &); Friend Double Operator (Matrix &, Double DBL);
Friend Double Operator- (Double DBL, Matrix &); Friend Double Operator- (Matrix &, Double DBL); Friend Ostream & Operator << (Ostream &, Matrix &); // Output Matrix (Void); // Default Construction Function Matrix (long N); // Unit Matrix Matrix (Dibimage & Dibimage); // Type Transition (converted image file into matrix for image calculation processing) Matrix (double * arraddress, long arrwidth; // Constructive Victor matrix (one line, arrwidth column) Matrix (double * arraddress, long arrheight, long arrival); // construct a two-dimensional matrix Matrix (Long Height, long width); // Constructs an empty matrix Matrix (Const Matrix &); // Copy constructor Virtual ~ matrix (void); // default analysis function / ********** Overloaded section -OverLoaded part *************** * /}; # incrude "stdafx.h" #include "./matrix.h"// matrix class - realize #define Sign ((b)> 0? FABS (a): -fabs (a )): Width (1), Height (1) {p = new double [1]; // width = 1; // Height = 1; // cout << "default constructor invoked. "<< Endl;} matrix :: matrix (long n) {height = width = n; p = new double [n * n]; for (long i = 0; i Matrix :: Matrix (Dibimage & Dibimage) {width (); height = dibimage.getHEight (); p = new double [width * height]; if (p == null) Assert (0); // Memory allocation fail LONG LLINEBYTES = Widthbytes (width * 8); lpstr src = :: Findibbits ((lpstr) :: Globalock ((hglobal) Dibimage.getHDIB ())); for (long (long i = 0; i } Matrix Matrix :: One (long n) {Matrix M (1, N); for (long i = 0; i LOG = false;} assert (log); Matrix M (Heightoffset * 2 1, Widthoffset * 2 1); for (long i = 0; i Bool Matrix :: ISPTV () {assert (width == Height); // is the square array can calculate BOOL RESULT = true; Matrix M; for (long i = 1; i <= height; i ) {m = this -> Submatrix (i); if (m.deter () <= 0) {result = false; break;}} returnrate;}} return result Matrix Matrix :: T () {DOUBLE * T = New Double [width * height]; for (long i = 0; i Double ** A, * WR, * Wi; long NN, M, L, K, J, ITS, I, Mmin; Double Z, Y, X, W, V, U, T, S, R, Q, P , anorm; long n = matrix.getwidth (); a = new double * [n 1]; wr = new double [n 1]; wi = new double [n 1]; for (i = 0; i For (i = 0; i Anorm = FABS (a [1] [1]); for (i = 2; i <= n; i ) for (j = (i-1); j <= n; j ) anorm = Fabs (a [a [ I] [j]); nn = n; T = 0.0; while (nn> = 1) {ITS = 0; do {for (l = nn; l> = 2; l -) {s = fabs (a [L-1] [L-1]) FABS (a [l] [l]); if (s == 0.0) s = anorm; IF (Fabs (a [L] [L-1]) S == s) Break;} x = a [nn] [nn]; if (l == nn) {WR [NN] = x T; Wi [nn -] = 0.0;} else {y = a [ NN-1] [NN-1]; W = a [NN] [NN-1] * a [NN-1] [NN]; if (l == (NN-1)) {P = 0.5 * (YX ); Q = p * p w; z = SQRT (Fabs (q)); x = T; IF (q> = 0.0) {z = p sign (Z, p); WR [NN-1] = WR [NN] = x z; if (z) WR [NN] = xw / z; Wi [NN-1] = Wi [NN] = 0.0;} else {WR [NN-1] = WR [NN ] = x p; Wi [NN-1] = - (Wi [nn] = z);} nn - = 2;} else {if (ITS == 30) Printf ("Too Many Itemions In HQR"); IF (ITS == 10 || ITS == 20) {t = x; for (i = 1; i <= nn; i ) a [i] [i] - = x; s = FABS (A [NN ] [NN-1]) FABS (a [NN-1] [NN-2]); y = x = 0.75 * s; w = -0.4375 * s * s;} ITS; for (m = NN-2); m> = L; M -) {z = a [m] [m]; r = xz; S = yz; p = (r * SW) / a [m 1] [m] a [m] [m 1]; q = a [m 1] [m 1] -zrs; r = A [M 2] [M 1]; s = FABS (P) Fabs (q) Fabs (R); P / = S; Q / = S; R / = S; IF (M == L Break; U = FABS (a [M] [M-1]) * (FABS (q) Fabs (R)); V = Fabs (P) * (Fabs (A [M-1] [M-1 ]) FABS (Z) FABS (a [M 1] [M 1])); IF (U V == V) Break;} for (i = m 2; i <= nn; i ) {a [i] [i-2] = 0.0; if (i! = (m 2) ) a [i] [i-3] = 0.0;} for (k = m; k <= nn-1; k ) {IF (k! = m) {P = a [k] [k-1]; q = a [k 1] [k-1]; r = 0.0; if (k! = (nn-1)) R = a [k 2] [k-1]; if (x = Fabs (P ) FABS (q) Fabs (R)) {p / = x; q / = x; r / = x;}}} f (s = SIGN (SQRT (P * P Q * q r * r) , p)) {if (k == m) {if (l! = m) a [k] [k-1] = -a [k] [k-1];} else a [k] [k- 1] = -s * x; p = S; x = p / s; y = q / s; z = r / s; q / = p; r / = p; for (j = k; j <= NN; j ) {p = a [k] [j] q * a [k 1] [j]; if (k! = (nn-1)) {p = r * a [k 2] [j]; a [k 2] [j] - = p * z;} a [k 1] [j] - = p * y; a [k] [j] - = p * x;} mmin = NN This-> width; j ) {(* this) [i] [j] / = Total;}} return;} void matrix :: store (const char * filename) {OFStream Fout (filename); int w = 5; For (long i = 0; i IF (j! = K) {PDBSRC [i * Nlen J] - = PDBSRC [i * Nlen K] * PDBSRC [K * Nlen J];} for (i = 0; i Return * this;} Matrix Matrix :: Operator (Matrix & m1) {assert (m1.height == height && m1.width == width); long tmpheight = m1.height; long tempwidth = m1.width; double * t = New Double [TmpWidth * Tmpheight]; for (long (long i = 0; i M1.Width * i j) = sum;}} Matrix M (t, height, m1.width); delete [] t; return m;} else {assert (0); // Unknown operation Return * this;} Matrix Operator * (Double Alpha, Matrix & M1) {Matrix M = m1; for (long i = 0; i 0); Matrix M = * this; for (long (long i = 0; i