[Fortran] 纯文本查看 复制代码
program mytp16
implicit none
integer n
double precision x,poly
double precision,allocatable::cf(:),npoly(:)
write(6,*)'input the nombre n'
read(5,*)n
write(6,*)'input the x'
read(5,*)x
allocate(cf(0:n),npoly(n))
cf=poly(n,npoly,cf,x)
npoly=poly(n,npoly,cf,x)
write(6,'("npoly(",i3,")=",d15.8)')n,npoly(n)
end program
double precision function poly(n,npoly,cf,x)
implicit none
integer i,n
double precision cf(0:n),npoly(0:n),x
open(15,file='the coefficient of npoly.txt')
do i=0,n
cf(i)=2.d0*i+1
write(15,*) cf(i)
end do
close(15)
open(15,file='the coefficient of npoly.txt')
do i=0,n
read(15,*) cf(i)
write(6,'("cf(",i3,")=",d15.8)')i,cf(i)
end do
close(15)
npoly(0)=cf(n)
npoly(1)=cf(n)*x+cf(n-1)
do i=2,n
npoly(i)=npoly(i-1)*x+cf(n-i)
end do
poly=npoly(n)
end function poly
! --------------------------------------------------
! Silverfrost FTN95 for Microsoft Visual Studio
! Free Format FTN95 Source File
! --------------------------------------------------
[Fortran] 纯文本查看 复制代码
Program mytp16
implicit none
integer n , i
Real(Kind=8) :: x , y
Real(Kind=8) , allocatable::cf(:)
write(*,*)'input the nombre n'
read(*,*)n
write(*,*)'input the x'
read(*,*)x
allocate( cf(0:n) )
open(15,file='the coefficient of npoly.txt')
Do i=0,n
cf(i) = 2.d0 * i + 1.d0
write(15,*) cf(i)
End Do
close(15)
y = poly ( cf , x )
write(*,'("y=",es13.6)') y
contains
Real(Kind=8) Function poly( cf , x ) result( y )
integer i , n
Real(Kind=8) :: cf(0:) , x
n = size( cf ) - 1
y = cf(n) * x + cf( n - 1 )
Do i = 2 , n
y = y * x + cf(n-i)
End Do
End Function poly
End Program mytp16