-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path二阶实对称阵的相似对角化.cpp
70 lines (60 loc) · 1.88 KB
/
二阶实对称阵的相似对角化.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include<iostream>
using namespace std;
int main()
{
int a[5],b[3],c[5],d[5],e[3];
int l,i,f,s,count=0;
cout<<"输入矩阵第一行:";
for(i=1;i<=2;i++)
{
cin>>a[i];
}
cout<<"\n输入矩阵第二行:";
for(i=3;i<=4;i++)
{
cin>>a[i];
}
for(i=-10;i<11;i++)
{
l=(a[1]-i)*(a[4]-i)-a[2]*a[3];
if(l==0)
{count++;
b[count]=i;}
}
cout<<"\n特征值为:"<<"x1="<<b[1]<<" x2="<<b[2]<<endl;
cout<<"当特征值为:"<<b[1]<<"时"<<endl;
c[1]=a[1]-b[1];
c[2]=a[2];
c[3]=a[3];
c[4]=a[4]-b[1];
for(i=-10;i<11;i++)
{
f=i*c[1]+c[2];
s=i*c[3]+c[4];
if(f==0&&s==0)
{d[1]=i;d[2]=1;}
}
cout<<"特征向量为:"<<d[1]<<"\n "<<d[2]<<endl;
e[1]=d[1]*d[1]+d[2]*d[2];
cout<<"单位化后特征向量的系数平方为"<<e[1]<<endl;
cout<<"当特征值为:"<<b[2]<<"时"<<endl;
c[1]=a[1]-b[2];
c[2]=a[2];
c[3]=a[3];
c[4]=a[4]-b[2];
for(i=-10;i<11;i++)
{
f=i*c[1]+c[2];
s=i*c[3]+c[4];
if(f==0&&s==0)
{d[3]=i;d[4]=1;}
}
cout<<"特征向量为:"<<d[3]<<"\n "<<d[4]<<endl;
e[2]=d[3]*d[3]+d[4]*d[4];
cout<<"单位化后特征向量的系数平方为"<<e[2]<<endl;
cout<<"该二阶矩阵相似对角化后为:"<<b[1]<<" 0"<<endl;
cout<<" "<<"0 "<<b[2]<<endl;
cout<<"正交可逆矩阵为:"<<"(根号"<<e[1]<<")*"<<d[1]<<" "<<"(根号"<<e[2]<<")*"<<d[3]<<endl;
cout<<" "<<"(根号"<<e[1]<<")*"<<d[2]<<" "<<"(根号"<<e[2]<<")*"<<d[4]<<endl;
return 0;
}