如何用 matlab编程实现10阶实对称矩阵对角化(求助)
最近在学习 matlab,遇到一个棘手的问题:将一个10阶实对称矩阵对角化。while语句是控制精度的,当所比较的值小于10^(-5)时跳出循环。break的位置好像一直没找对,程序始终无法循环。恳请各位高手前辈指点!程序如下:a1=[-7645,0,0,0,0,0,536.37,0,0,-90;0,-7555,0,0,63.63,0,0,663.63,0,0;0,0,-7555,0,0,63.63,0,0,663.63,0;0,0,0,-7645,0,0,-90,0,0,663.63;0,63.63,0,0,-7500,0,0,-90,0,0;0,0,63.63,0,0,-7500,0,0,-90,0;536.37,0,0,-90,0,0,11400,0,0,0;0,663.63,0,0,-90,0,0,11400,0,0;0,0,663.63,0,0,-90,0,0,11400,0;-90,0,0,663.63,0,0,0,0,0,11400]
max=abs(a1(1,2))
for i=1:9
for j=(i+1):10
if abs(a1(i,j))>max
max=abs(a1(i,j))
p=i
q=j
end
end
end
while abs(a1(p,q)) >10^(-5)
c=2*a1(p,q)/(a1(p,p)-a1(p,q))
n=1/sqrt(1+c^2)
m=sqrt((1+n)/2)
for j=1:10
if j~=p,j~=q
a2(p,j)=a1(p,j)*m+a1(p,j)*c*(1/sqrt(1+c^2))/(2*m)
a2(j,p)=a1(p,j)*m+a1(p,j)*c*n/(2*m)
a1(p,j)=a2(p,j)
a1(j,p)=a2(j,p)
else
a2(p,p)=a1(p,p)*(1+n)+c*n*a1(p,q)+a1(p,q)*(1-n)/2
a2(q,q)=a1(p,p)*(1-n)/2-c*n*a1(p,q)+a1(q,q)*(1+n)
a1(p,p)=a2(p,p)
a1(q,q)=a2(q,q)
end
end
break
end