Документ взят из кэша поисковой машины. Адрес оригинального документа : http://www.mrao.cam.ac.uk/~rachael/compphys/examples/runge.f90
Дата изменения: Tue Oct 18 17:08:16 2005
Дата индексирования: Tue Oct 2 10:48:35 2012
Кодировка:

Поисковые слова: п п п п п п п п п п п п
! Program to demonstrate the Runge-Kutta method on
! dy/dx = y over the interval [0,1]

program rungekutta

implicit none

integer, parameter :: n = 10 ! number of divisions
integer, parameter :: dp = kind(1.0d0) ! kind for double precision
integer :: i ! loop counter
real(dp) :: x, y, h, k1, k2 ! integration variables

! interval spacing
h = 1.0_dp / n

! initial condition y(0) = 1
y = 1.0_dp

! open file for results
open(10,file='runge.dat')

! perform Runge-Kutta (midpoint) method
do i = 0, n
x = i * h
write(10,*) x, y
k1 = h * f(x,y)
k2 = h * f(x+0.5_dp*h,y+0.5_dp*k1)
y = y + k2
end do

! close file
close(10)

contains

! this function provides the value of dybydx at (x,y)
real(dp) function f(x,y)

real(dp), intent(in) :: x, y

f = y

end function f

end program rungekutta