资源简介
利用QR方法求解一般实矩阵的特征值的方法,包括求解得到的复数特征值。
代码片段和文件信息
#include
#include
#include
#include
using namespace std;
void hhbg (double a[5][5]int n);
void a_hhqr (double a[5][5]int ndouble * udouble * vdouble epsint jt) ;
int main(int argc char *argv[])
{
QCoreApplication b(argc argv);
int ijjt=60;//jt为迭代次数
double eps=0.000001;//迭代精度
static double u[5]v[5];
static double a[5][5]={{1.06.0-3.0-1.07.0}{8.0-15.018.05.04.0}
{-2.011.09.015.020.0}{-13.02.021.030.0-6.0}
{17.022.0-5.03.06.0}};
/* static double a[5][5]={{110.94126.185678.26783-3}{1714.647124.87325.7797-5}
{0-19.269935.00965.839117.1765}{00-61.3733-45.55446.18675}
{000-22.852625.8977}};*/
hhbg(a5);//把矩阵进行赫申伯格换
//输出赫申伯格矩阵
printf(“MAT H is:\n“);
for (i=0;i<=4;i++)
{
for(j=0;j<=4;j++)
printf(“%f “a[i][j]);
printf(“\n“);
}
printf(“\n“);
a_hhqr (a5 uvepsjt);//对矩阵进行QR变换求特征值
//输出矩阵特征值
for(i=0;i<=4;i++)
{
if(v[i]<0)
printf(“ %f%fi\n “u[i]v[i]);
else if(v[i]>0)
printf(“ %f+%fi\n “u[i]v[i]);
else
printf(“ %f\n “u[i]);
}
return b.exec();
}
void hhbg (double a[5][5]int n) //执行初等相似变换
{
int ijk;
double dt;
for (k=1; k<=n-2; k++)
{
d=0.0;
for (j=k; j<=n-1; j++)
{
t=a[j][k-1];
if (fabs(t)>fabs(d)) { d=t; i=j;}
}
if (fabs(d)+1.0!=1.0)
{
if (i!=k)
{
for (j=k-1; j<=n-1; j++)
{
t=a[i][j]; a[i][j]=a[k][j]; a[k][j]=t;
}
for (j=0; j<=n-1; j++)
{
t=a[j][i]; a[j][i]=a[j][k]; a[j][k]=t;
}
}
for (i=k+1; i<=n-1; i++)
{
t=a[i][k-1]/d; a[i][k-1]=0.0;
for (j=k; j<=n-1; j++)
a[i][j]=a[i][j]-t*a[k][j];
for (j=0; j<=n-1; j++)
a[j][k]=a[j][k]+t*a[j][i];
}
}
}
}
void a_hhqr (double a[5][5]int ndouble * udouble * vdouble epsint Max) //用QR方法计算全部特征值
{
int mitijkl;
double bcwgxypqrxsefzy;
it=0; m=n;
while (m!=0)
{
l=m-1;
while ((l>0)&&(fabs(a[l][l-1])>eps*
(fabs(a[l-1][l-1])+fabs(a[l][l])))) l=l-1;
if (l==m-1)
{
u[m-1]=a[m-1][m-1]; v[m-1]=0.0;
m=m-1; it=0;
}
else if (l==m-2)
{
b=-(a[m-1][m-1]+a[m-2][m-2]);
c=a[m-1][m-1]*a[m-2][m-2]-a[m-1][m-2]*a[m-2][m-1];
- 上一篇:微波炉proteus仿真
- 下一篇:MFC和MATLAB混合编程
评论
共有 条评论