资源简介
一个vc开发的复数矩阵用qr分解方法求解逆矩阵的V刹动态库源码,以在vc6平台调试通过,原始矩阵是4维的,可扩展
代码片段和文件信息
#include “QrInv.h“
int c_qrs(int ndouble ** realdouble ** imgdouble **R_realdouble** R_imgdouble ** Q_realdouble ** Q_img)
{
int ncount = 0;
double ** HMatReal = new double *[n];
double ** HMatImg = new double *[n];
double ** ResMatReal= new double *[n];
double ** ResMatImg = new double *[n];
for ( int i = 0; i < n; i++)
{
HMatReal[i] = new double[n];
HMatImg[i] = new double[n];
ResMatReal[i] = new double[n];
ResMatImg[i] = new double[n];
}
for (i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
if (i == j)
{
Q_real[i][j] = 1;
}
else
{
Q_real[i][j] = 0;
}
Q_img[i][j] = 0;
}
}
c_copmatris(n R_realR_imgrealimg);
for ( i = n; i > 1; i-- ) // 总体循环,进行QR分解
{
double * a1Real = new double [i];
double * a1Img = new double[i];
double * e1Real = new double[i];
double * e1Img = new double[i];
double * w1Real = new double [i];
double * w1Img = new double[i];
ncount++;
for (int j = 0; j < n; j++)
{
for (int k = 0; k < n; k++)
{
if (j == k)
{
HMatReal[j][k] = 1;
}
else
{
HMatReal[j][k] = 0;
}
HMatImg[j][k] = 0;
}
} // 初始化单位矩阵
for ( j = 0; j < i; j++) // 获取每次a向量
{
a1Real[j] = R_real[(n -i) + j][n - i]; //获取第一例实数部分
a1Img[j] = R_img[(n -i) + j][n - i]; //获取第一例虚数部分
if (j == 0)
{
e1Real[j] = a1Real[j]; // 构造单位向量实部(共轭)
e1Img[j] = a1Img[j];
}
else
{
e1Real[j] = 0; // 构造单位向量实部
e1Img[j] = 0;
}
// 构造单位向量虚部
}
double ** MatReal = new double *[i];
double ** MatImg = new double *[i];
for (j = 0; j < i; j++)
{
MatReal[j] = new double[i];
MatImg[j] = new double[i];
}
double norm = c_norm(ia1Reala1Img); // 求a向量模
// 判断向量a的第一个元素是否为复数
if (norm == 0)
{
return -2; // 矩阵不可逆该列出现全零现象,该矩阵不可逆
}
if (e1Img[0] != 0)
{
double eNorm = sqrt(e1Real[0] * e1Real[0] + e1Img[0] * e1Img[0]);
e1Real[0] = (norm / eNorm) * e1Real[0];
e1Img[0] = (norm / eNorm) * e1Img[0] ;
} else
{
e1Real[0] = 1;
e1Img[0] = 0;
c_multvector(i norm e1Reale1Img); // 实数与向量乘积
}
c_subvector(i a1Reala1Img e1Reale1Img); //向量相减
norm = c_norm(ia1Reala1Img); // 求相减后的模
if (norm < e) //如果列向量为单位向量,则进行下一次循环 模小于最小精度,认为为0
{
continue;
}
c_dividvector(i norma1Reala1Img); // 除以模
c_mutvectors(i a1Reala1Imga1Reala1ImgMatRealMatImg); // 向量相乘得到
for (j = 0; j < i; j++) // I - 2W*W‘
{
for (int k = 0; k < i; k++)
{
if (k == j)
{
MatReal[j][k] = 1 - 2 * MatReal[j][k];
}
else
{
MatReal[j][k] = -2 * MatReal[j][k];
}
MatImg[j][k] = -2 * MatImg[j][k];
}
}
// 求得H1(MatRealMatImg) H1 * A
for (j = 0; j < i; j++
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 13155 2014-02-21 14:04 COMMATRQR_DLL\QrInv.cpp
文件 1873 2014-02-21 11:00 COMMATRQR_DLL\QrInv.h
目录 0 2014-09-18 17:34 COMMATRQR_DLL
----------- --------- ---------- ----- ----
15028 3
- 上一篇:C++ASCII文件练习的几个文件
- 下一篇:几种控制方法的C语言编程.
评论
共有 条评论