资源简介
自己写的一个基于Givens矩阵分解的简单示例程序,不要资源分,仅供参考。
代码片段和文件信息
#include
using namespace std;
void Givens(double ** m int row int column int N);
void Matrix_Mutil(double ** m double **n int N);
int main()
{
int N;
cout << “input the Matrix dimension N“ << endl;
cin >> N;
cout << “input “ << N << “*“ << N << “ Matrix:“ << endl;
double **matx = new double *[N];
for (int i = 0; i < N; i++)
matx[i] = new double[N];
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
cin >> matx[i][j];
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
cout << matx[i][j]<<“ “;
cout << endl;
}
if (N <= 1)
return 1;
for (int i = 0; i < N-1; i++)
{
for (int j = i + 1; j < N; j++)
{
if (abs(matx[j][i]) <= 0.0001)
continue;
else{
Givens(matx j i N);
}
}
}
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
cout << matx[i][j] << “ “;
cout << endl;
}
for (int i = 0; i < N; i++)
delete matx[i];
delete matx;
return 1;
}
void Givens(double ** m int row int columnint N)
{
double **Gs = new double *[N];
for (int i = 0; i < N; i++)
Gs[i] = new double[N];
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
Gs[i][j] = 0;
for (int i = 0; i < N; i++)
Gs[i][i] = 1;
double r = sqrt(m[column][column] * m[column][column] + m[row][column] * m[row][column]);
double C = m[column][column] / r;
double S = m[row][column] / r;
Gs[row][row] = C;
Gs[column][column] = C;
Gs[column][row] = S;
Gs[row][column] = -S;
//cout << “output Gs: “ << endl;
//for (int u = 0; u < N; u++)
//{
// for (int v = 0; v < N; v++)
// cout << Gs[u][v] << “ “;
// cout << endl;
//}
Matrix_Mutil(Gs m N);
for (int i = 0; i < N; i++)
delete Gs[i];
delete Gs;
}
void Matrix_Mutil(double ** m double **n int N){
double **tmp = new double *[N];
for (int i = 0; i < N; i++)
tmp[i] = new double[N];
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
double tmp_rs = 0;
for (int k = 0; k < N; k++)
tmp_rs = tmp_rs + m[i][k] * n[k][j];
tmp[i][j] = tmp_rs;
}
}
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
n[i][j] = tmp[i][j];
}
}
for (int i = 0; i < N; i++)
delete tmp[i];
delete tmp;
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 69120 2015-10-29 14:18 GivensMatrix\Debug\GivensMatrix.exe
文件 867616 2015-10-29 14:18 GivensMatrix\Debug\GivensMatrix.ilk
文件 1257472 2015-10-29 14:18 GivensMatrix\Debug\GivensMatrix.pdb
文件 1323 2015-10-29 14:18 GivensMatrix\GivensMatrix\Debug\GivensMatrix.log
文件 614 2015-10-29 14:18 GivensMatrix\GivensMatrix\Debug\GivensMatrix.tlog\cl.command.1.tlog
文件 11214 2015-10-29 14:18 GivensMatrix\GivensMatrix\Debug\GivensMatrix.tlog\CL.read.1.tlog
文件 420 2015-10-29 14:18 GivensMatrix\GivensMatrix\Debug\GivensMatrix.tlog\CL.write.1.tlog
文件 156 2015-10-29 14:18 GivensMatrix\GivensMatrix\Debug\GivensMatrix.tlog\GivensMatrix.lastbuildstate
文件 1090 2015-10-29 14:18 GivensMatrix\GivensMatrix\Debug\GivensMatrix.tlog\li
文件 2360 2015-10-29 14:18 GivensMatrix\GivensMatrix\Debug\GivensMatrix.tlog\li
文件 394 2015-10-29 14:18 GivensMatrix\GivensMatrix\Debug\GivensMatrix.tlog\li
文件 157651 2015-10-29 14:18 GivensMatrix\GivensMatrix\Debug\Source.obj
文件 265216 2015-10-29 14:18 GivensMatrix\GivensMatrix\Debug\vc120.idb
文件 339968 2015-10-29 14:18 GivensMatrix\GivensMatrix\Debug\vc120.pdb
文件 4025 2015-10-27 21:29 GivensMatrix\GivensMatrix\GivensMatrix.vcxproj
文件 960 2015-10-27 21:29 GivensMatrix\GivensMatrix\GivensMatrix.vcxproj.filters
文件 2279 2015-10-29 14:18 GivensMatrix\GivensMatrix\Source.cpp
文件 7208960 2015-10-29 14:20 GivensMatrix\GivensMatrix.sdf
文件 982 2015-10-27 21:14 GivensMatrix\GivensMatrix.sln
..A..H. 19456 2015-10-29 14:20 GivensMatrix\GivensMatrix.v12.suo
目录 0 2015-10-29 14:18 GivensMatrix\GivensMatrix\Debug\GivensMatrix.tlog
目录 0 2015-10-29 14:18 GivensMatrix\GivensMatrix\Debug
目录 0 2015-10-27 21:29 GivensMatrix\Debug
目录 0 2015-10-29 14:18 GivensMatrix\GivensMatrix
目录 0 2015-12-05 10:41 GivensMatrix
----------- --------- ---------- ----- ----
10211276 25
评论
共有 条评论