DsFqIEnm 数值分析–4–高斯消元法(1) - Big Bug Ban

Big Bug Ban

兴趣 践行 创新

数值分析–4–高斯消元法(1)

 

/*
* For:    Histogiagram
* File:   diagram.h
* Author: princehaku
*
* Created on 2009
年10月3日, 下午3:31

*/

#ifndef diagram_H
#define diagram_H

namespace diagram {
class DIAGRAM_T {
private:
//行数
int rows;
//
列数
int cols;                                                                         //
二维矩阵
double DIAGRAM[30][30];
public:
DIAGRAM_T(int rows, int cols) {
this->rows = rows;
this->cols = cols;
//
申请矩阵存储空间
//this->DIAGRAM=(int **)(new int[rows*cols]);
//~ int **DIAGRAM= new int*[rows+3]; //
第一维,
//~ 
//~ for( int i=0; i<rows; i++)
//~ {
//~ DIAGRAM[i] = new int[cols+3];  //
分配第二维,每一行的空间。
//~ } 
//~ //
溢出

//~ if (!DIAGRAM) {
//~ cout << "Out of Memory";
//~ }
}

/**
+———————————————————-
* 
得到单元格值
+———————————————————-
* @access public
+———————————————————-
* @param integer rows  
行
* @param integer rows  
列

+———————————————————-
* @return int
+———————————————————-
*/

double getValue(int row, int col) {
return this->DIAGRAM[row - 1][col - 1];
}
/**
+———————————————————-
* 
设定某单元格的值
+———————————————————-
* @access public
+———————————————————-
* @param integer rows  
行
* @param integer rows  
列
* @param integer value 
值

+———————————————————-
* @return bool
+———————————————————-
*/

bool setValue(int rows, int cols, double value) {            
this->DIAGRAM[rows - 1][cols - 1] = value;
//cout<<"rows"<<rows<<"cols"<<cols<<"cg to"<<value<<endl;
return true;
}
/**
+———————————————————-
* 
转置矩阵
+———————————————————-
* @access public
+———————————————————-
* @return bool
+———————————————————-
*/

bool transpose() {
double tmp;
for (int i = 0; i < this->rows; i++) {
for (int j = 0; j < this->cols; j++) {
if (i < j) {
tmp = this->DIAGRAM[i][j];
this->DIAGRAM[i][j] = this->DIAGRAM[j][i];
this->DIAGRAM[j][i] = tmp;
}
}
}
return true;
}


/**
+———————————————————-
* 
列交换
+———————————————————-
* @access public
+———————————————————-
* @return bool
+———————————————————-
*/

bool l(int rowA,int rowB) {
double tmp;

for (int j = 0; j < this->cols; j++) {
tmp=this->DIAGRAM[rowA–1][j];
this->DIAGRAM[rowA–1][j]=this->DIAGRAM[rowB–1][j];
this->DIAGRAM[rowB–1][j]=tmp;
}

return true;
}
/**
+———————————————————-
* 
行交换
+———————————————————-
* @access public
+———————————————————-
* @return bool
+———————————————————-
*/

bool h(int colA,int colB) {
double tmp;

for (int i = 0; i < this->rows; i++) {
tmp=this->DIAGRAM[i][colA–1];
this->DIAGRAM[i][colA–1]=this->DIAGRAM[i][colB–1];
this->DIAGRAM[i][colB–1]=tmp;
}

return true;
}
/**
+———————————————————-
* 
打印矩阵
+———————————————————-
* @access public
+———————————————————-
* @return void
+———————————————————-
*/

void print_g() {

for (int i = 0; i < this->rows; i++) {
for (int j = 0; j < this->cols; j++) {
cout << this->DIAGRAM[i][j] << "  ";
}
cout << endl;
}
}

Written by princehaku

15 10 月, 2009 at 10:22 上午

Posted in c/c++

without comments

Leave a Reply