program ex0001
integer n
real x1,x2,x,f1,f2,fx,eps
real,allocatable::d(,e(
write(*,*) "lease enter n:"
read(*,*) n
allocate(d(n),e(n-1)) ! d是对角元素,e是非对角元素
eps=1.0E-6
fx=1.0
do j=1,n
d(j)=-2
end do
do j=1,n-1
e(j)=1
end do
!write(*,*) "lease enter array d and e:"
!read(*,*) d,e
a1=d(1)-e(1)
a2=d(1)-2*e(1)
a3=d(1)+e(1)
a4=d(1)+2*e(2)
y1=min(a1,a2)
y2=max(a4,a3)
y=(y2-y1)/n
x1=y1
x2=y1+y
write(*,*)"矩阵的特征值为:"
do m=1,n
temp=x2
10 if(abs(fx)>eps) then
x=(x1+x2)/2
f1=MValue(x1,n,d,e)
f2=MValue(x2,n,d,e)
fx=MValue(x,n,d,e)
if (fx*f1>0) then
x1=x
else
x2=x
end if
go to 10
end if
print*,"--------------------"
write(*,*) x
x1=temp
x2=temp+y
z=(x1+x2)/2
fx=MValue(z,n,d,e)
end do
print*,"--------------------"
contains
real function mValue(x,n,d,e) !对称三对角矩阵多项式展开
Integer n,i
real x
real d(n),e(n-1),s(n)
S(1)=x-d(1)
S(2)=(x-d(1))*(x-d(2))-e(1)**2
Do i=3,n
S(i)=(x-d(i))*s(i-1)-e(i-1)**2*s(i-2)
End do
mValue=s(n)
return
End function mValue
end
帮我 解释下 这个程序吧,麻烦各位了 |