FORTRAN90程序设计

FORTRAN90程序设计,第1张

Program Main

Implicit None

Integer :: i , iCount

iCount = 0

Do i = 351 , 432

If( Mod(i,3)/=0 And(Mod(i,8)/=0) ) then

iCount = iCount + 1

EndIf

End Do

Write(,) iCount

End Program Main

这个是在fortran95程序设计里的p205的例题,这个问题我也遇到过,研究了一下,我认为是:module里定义的值,不能通过子程序形参的形式调用。一旦调用,就会出现这个错误。如果是在大程序里遇到这样的问题,就可以像例子一样,call sub()的形式。如果遇到合理的解释,还望大家共同讨论

我想本题的关键在于理论的分析。由于炮d的轨迹为二次曲线方程,因次炮d在二次曲线对称轴

x=007/(200000125)处上升最大高度。另外炮d发射时和落地时距地面的高度均为0。因此令f(x)=0求出发射点和落地点的横坐标x1,x2,相减之后(x2-x1),就是导d前行的最远距离。下面是程序,望对你有帮助!

程序:

module tool

implicit none

real8::distance !导d上升的最大高度

real8::high !导d飞行的最远距离

contains

real8 function f(x)

real8::x

f=-00000125x2+007x-50 !导d飞行曲线的轨道方程

!f=x2+1

end function

real8 function binroot(f,x1,x2)!二分法求方程的根(零点)

real8,external::f

real8::x1,x2,x0

do while(f(x1)f(x2)<1e-8andabs(x1-x2)>1e-8)

x0=(x1+x2)/2

if(f(x0)f(x2)<1e-8)then

x1=x0

elseif(f(x1)f(x0)<1e-8)then

x2=x0

endif

enddo

binroot=(x1+x2)/2

end function

subroutine solveproblem(f)!求解导d高度及飞行最远距离的函数

real8,external::f

real8::x0=007/(200000125)!导d轨道的对称轴

real8::xL,xR,x1,x2 !xL为二分法的左端点,用来求轨道的根x1;xR为二分法的右端点,用来求轨道的根x2

high=f(x0)

xL=x0-10

xR=x0+10

do while(f(xL)f(x0)>1e-8)

xL=xL-10

enddo

do while(f(xR)f(x0)>1e-8)

xR=xR+10

enddo

x1=binroot(f,xL,x0)

x2=binroot(f,x0,xR)

distance=x2-x1

end subroutine

end module

program main

use tool

implicit none

call solveproblem(f)

write(,10) high,distance

10 format("导d上升的最大高度",f/,"导d前行的最远距离",f)

stop

end

program randomEG

implicit none

integer :: k, i,j, temp, n=10000

real :: r

integer, dimension(8) :: values 

! Declare an assumed shape, dynamic array

integer, dimension(:), allocatable :: seed

integer, dimension(:), allocatable :: results

! gfortran subroutine to return date and time information 

! from the real time system clock Works down to milliseconds 

! and stores the eight return values in array values

call date_and_time(VALUES=values)

! restart the state of the pseudorandom number generator

! k = minimum size of seed (12 on my system)

call random_seed(size=k)

! allocate memory to seed

allocate(seed(k))

allocate(results(n))

! assign information in values to seed

seed(:) = values(:)

! seed the random number generator

call random_seed(put=seed)

do i=1,n

    results(i) = irand()

end do

do i=1,n

    do j=i+1,n

        if (results(i) > results(j)) then

            temp = results(i)

            results(i) = results(j)

            results(j) = temp

        endif

    enddo

enddo

do i=1,n

    print , results(i)

end do

end program randomEG

以上就是关于FORTRAN90程序设计全部的内容,包括:FORTRAN90程序设计、我用fortran90 写程序时出现了这样的问题,谁能告诉我是怎么回事啊、fortran程序求编辑等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zz/10088535.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-05
下一篇 2023-05-05

发表评论

登录后才能评论

评论列表(0条)

保存