主题:[讨论]请问为什么得到的值都是一样的?
请问为什么以下程序得到的A(l,2),k2,P2的值都是一样的呢?
以下是输出:
A(l,2) k2
-0.0000000 1.0000000
1.0000000 1.0000000
0.0000000 1.0000000
A(l,0) P2
-5.0000000 1.0000000
0.0000000 1.0000000
5.0000000 1.0000000
以下是编写的程序:
Function fun_f(temp)
IMPLICIT NONE
REAL, INTENT(IN) :: temp
REAL :: fun_f
fun_f=(1.0/(1.0+temp**2))
RETURN
END Function fun_f
Function funk(va1,va2)
IMPLICIT NONE
REAL, INTENT(IN) :: va1,va2
REAL :: funk
funk=(va1*va2)
RETURN
END Function funk
PROGRAM interpolation_errors
IMPLICIT NONE
REAL :: q,k2=0.0,k6=0.0,k8=0.0,P2=0.0,P6=0.0,P8=0.0
INTEGER :: i,j,k,l,m,n
REAL :: A(0:2,0:2),B(0:6,0:2),C(0:8,0:2)
REAL, external :: fun_f,funk
DO i=2,8
IF(i==2) THEN
q=(10.0/2.0)
A(0:2,0:2)=1.0
A(0,0)=-5.0
A(0,1)=fun_f(A(0,0))
DO j=1,2
A(j,0)=(A(j-1,0)+q)
A(j,1)=fun_f(A(j,0))
ENDDO
DO k=0,2
DO n=0,2
IF(k/=n) THEN
A(k,2)=(A(k,2)*(A(l,0)-A(n,0))/(A(k,0)-A(n,0)))
ENDIF
ENDDO
ENDDO
DO m=0,2
k2=(k2+funk(A(m,1),A(m,2))) !compute the value of pai(x)
ENDDO
P2=(k2/(1.0+A(l,0)**2)) !compute the value of pai(x)*f(x)
OPEN(10,file='test00.dat')
DO l=0,2
WRITE(10,*)A(l,2),k2
ENDDO
CLOSE(10)
OPEN(10,file='test0.dat')
DO l=0,2
WRITE(10,*)A(l,0),P2
ENDDO
CLOSE(10)
ENDIF
IF(i==6) THEN
q=(10.0/6.0)
B(0:6,0:2)=1.0
B(0,0)=-5.0
B(0,1)=fun_f(B(0,0))
DO j=1,6
B(j,0)=(B(j-1,0)+q)
B(j,1)=fun_f(B(j,0))
ENDDO
DO k=0,6
DO n=0,6
IF(k/=n) THEN
B(k,2)=(B(K,2)*(B(l,0)-B(n,0))/(B(k,0)-B(n,0)))
ELSE
CYCLE
ENDIF
ENDDO
ENDDO
DO m=0,6
k6=(k6+B(m,1)*B(m,2))
ENDDO
P6=(k6/(1.0+B(l,0)**2))
OPEN(10,file='test1.dat')
DO l=0,6
WRITE(10,*)B(l,0),P6
ENDDO
CLOSE(10)
ENDIF
IF(i==8) THEN
q=(10.0/8.0)
C(0:6,0:2)=1.0
C(0,0)=-5.0
C(0,1)=fun_f(C(0,0))
DO j=1,8
C(j,0)=(C(j-1,0)+q)
C(j,1)=fun_f(C(j,0))
ENDDO
DO k=1,8
DO n=1,8
IF(k/=n) THEN
C(k,2)=(C(K,2)*(C(l,0)-C(n,0))/(C(k,0)-C(n,0)))
ELSE
CYCLE
ENDIF
ENDDO
ENDDO
DO m=0,8
k8=(k8+C(m,1)*C(m,2))
ENDDO
P8=(k8/(1.0+C(l,0)**2))
OPEN(10,file='test2.dat')
DO l=0,8
WRITE(10,*)C(l,0),P8
ENDDO
CLOSE(10)
ENDIF
ENDDO
END PROGRAM interpolation_errors
以下是输出:
A(l,2) k2
-0.0000000 1.0000000
1.0000000 1.0000000
0.0000000 1.0000000
A(l,0) P2
-5.0000000 1.0000000
0.0000000 1.0000000
5.0000000 1.0000000
以下是编写的程序:
Function fun_f(temp)
IMPLICIT NONE
REAL, INTENT(IN) :: temp
REAL :: fun_f
fun_f=(1.0/(1.0+temp**2))
RETURN
END Function fun_f
Function funk(va1,va2)
IMPLICIT NONE
REAL, INTENT(IN) :: va1,va2
REAL :: funk
funk=(va1*va2)
RETURN
END Function funk
PROGRAM interpolation_errors
IMPLICIT NONE
REAL :: q,k2=0.0,k6=0.0,k8=0.0,P2=0.0,P6=0.0,P8=0.0
INTEGER :: i,j,k,l,m,n
REAL :: A(0:2,0:2),B(0:6,0:2),C(0:8,0:2)
REAL, external :: fun_f,funk
DO i=2,8
IF(i==2) THEN
q=(10.0/2.0)
A(0:2,0:2)=1.0
A(0,0)=-5.0
A(0,1)=fun_f(A(0,0))
DO j=1,2
A(j,0)=(A(j-1,0)+q)
A(j,1)=fun_f(A(j,0))
ENDDO
DO k=0,2
DO n=0,2
IF(k/=n) THEN
A(k,2)=(A(k,2)*(A(l,0)-A(n,0))/(A(k,0)-A(n,0)))
ENDIF
ENDDO
ENDDO
DO m=0,2
k2=(k2+funk(A(m,1),A(m,2))) !compute the value of pai(x)
ENDDO
P2=(k2/(1.0+A(l,0)**2)) !compute the value of pai(x)*f(x)
OPEN(10,file='test00.dat')
DO l=0,2
WRITE(10,*)A(l,2),k2
ENDDO
CLOSE(10)
OPEN(10,file='test0.dat')
DO l=0,2
WRITE(10,*)A(l,0),P2
ENDDO
CLOSE(10)
ENDIF
IF(i==6) THEN
q=(10.0/6.0)
B(0:6,0:2)=1.0
B(0,0)=-5.0
B(0,1)=fun_f(B(0,0))
DO j=1,6
B(j,0)=(B(j-1,0)+q)
B(j,1)=fun_f(B(j,0))
ENDDO
DO k=0,6
DO n=0,6
IF(k/=n) THEN
B(k,2)=(B(K,2)*(B(l,0)-B(n,0))/(B(k,0)-B(n,0)))
ELSE
CYCLE
ENDIF
ENDDO
ENDDO
DO m=0,6
k6=(k6+B(m,1)*B(m,2))
ENDDO
P6=(k6/(1.0+B(l,0)**2))
OPEN(10,file='test1.dat')
DO l=0,6
WRITE(10,*)B(l,0),P6
ENDDO
CLOSE(10)
ENDIF
IF(i==8) THEN
q=(10.0/8.0)
C(0:6,0:2)=1.0
C(0,0)=-5.0
C(0,1)=fun_f(C(0,0))
DO j=1,8
C(j,0)=(C(j-1,0)+q)
C(j,1)=fun_f(C(j,0))
ENDDO
DO k=1,8
DO n=1,8
IF(k/=n) THEN
C(k,2)=(C(K,2)*(C(l,0)-C(n,0))/(C(k,0)-C(n,0)))
ELSE
CYCLE
ENDIF
ENDDO
ENDDO
DO m=0,8
k8=(k8+C(m,1)*C(m,2))
ENDDO
P8=(k8/(1.0+C(l,0)**2))
OPEN(10,file='test2.dat')
DO l=0,8
WRITE(10,*)C(l,0),P8
ENDDO
CLOSE(10)
ENDIF
ENDDO
END PROGRAM interpolation_errors