Fortran90编程题,在线等,急

2025-02-27 09:29:53
推荐回答(1个)
回答1:

最后输出结果:

   3.1308185099450458     
   3.1415964015690721     
   3.1415483065637204     
   3.0710763125803080     
   3.1415483065637204     
   3.1415964015690721     
   3.1299213923996372

我的程序

module alpha
implicit none
contains
function fun(x)
real*8::x,sx,fun
integer::n,i
fun=0
i=1
sx=(-1)**(i+1)*i*sin(2*i*x)/(4*i**2-1)**2
do while(abs(sx)>=1e-9)
fun=fun+sx
i=i+1
sx=(-1)**(i+1)*i*sin(2*i*x)/(4*i**2-1)**2
enddo
fun=fun*16/(x*cos(x))
end function fun
end module alpha

program comm
use alpha
implicit none
real*8::x(7),y(7)
integer::i
open(8,file='MYF2.DAT')
open(9,file='MYF2.OUT')
read(8,*)x
do i=1,7
y(i)=fun(x(i))
write(9,*)y(i)
enddo
write(*,*)'输出成功'
read(*,*)
end program comm

希望帮到你!!