Rk4 Fortran Code



In the following table, each line/entry contains the program file name, the page number where it can be found in the textbook, and a brief description. Click on the program name to display the source code, which can be downloaded.

Runge kutta fehlberg fortran code
Chapter 1: Introduction
first.f906-7First programming experiment
pi.f90 8Simple code to illustrate double precision
Chapter 2: Number Representation and Errors
oct.f90 49Print in octal format
hex.f90 50Print in hexadecimal format
numbers.f90 60-61Print internal machine representation of various numbers
xsinx.f90 77-79Example of carefully programming f(x) = x - sinx
Chapter 3: Locating Roots of Equations
bisection.f9094-95Bisection method
rec_bisection.f9095-96Recursive version of bisection method
newton.f90106-107Sample Newton method
secant.f90127-128Secant method
Chapter 4: Interpolation and Numerical Differentiation
coef.f90152-155Newton interpolation polynomial at equidistant pts
deriv.f90185-186Derivative by center differences/Richardson extrapolation
Chapter 5: Numerical Integration
sums.f90200Upper/lower sums experiment for an integral
trapezoid.f90207Trapezoid rule experiment for an integral
romberg.f90223-224 Romberg arrays for three separate functions
Chapter 6: More on Numerical Integration
rec_simpson.f90241Adaptive scheme for Simpson's rule
Chapter 7: Systems of Linear Equations
ngauss.f90270-271Naive Gaussian elimination to solve linear systems
gauss.f90285-287Gaussian elimination with scaled partial pivoting
tri.f90301-302Solves tridiagonal systems
penta.f90304Solves pentadiagonal linear systems
Chapter 8: More on Systems of Linear Equations
Chapter 9: Approximation by Spline Functions
spline1.f90385Interpolates table using a first-degree spline function
spline3.f90404-406Natural cubic spline function at equidistant points
bspline2.f90427-428Interpolates table using a quadratic B-spline function
schoenberg.f90430-431Interpolates table using Schoenberg's process
Chapter 10: Ordinary Differential Equations
euler.f90448-449Euler's method for solving an ODE
taylor.f90451Taylor series method (order 4) for solving an ODE
rk4.f90462-463Runge-Kutta method (order 4) for solving an IVP
rk45.f90472-473Runge-Kutta-Fehlberg method for solving an IVP
rk45ad.f90474Adaptive Runge-Kutta-Fehlberg method
Chapter 11: Systems of Ordinary Differential Equations
taylorsys1.f90489-490Taylor series method (order 4) for systems of ODEs
taylorsys2.f90491Taylor series method (order 4) for systems of ODEs
rk4sys.f90491-493,496Runge-Kutta method (order 4) for systems of ODEs
amrk.f90510-513 Adams-Moulton method for systems of ODEs
amrkad.f90513Adaptive Adams-Moulton method for systems of ODEs
Chapter 12: Smoothing of Data and the Method of Least Squares
Chapter 13: Monte Carlo Methods and Simulation
test_random.f90562-563Example to compute, store, and print random numbers
coarse_check.f90564Coarse check on the random-number generator
double_integral.f90574-575Volume of a complicated 3D region by Monte Carlo
volume_region.f90575-576Numerical value of integral over a 2D disk by Monte Carlo
cone.f90576-577 Ice cream cone example
loaded_die.f90581Loaded die problem simulation
birthday.f90583Birthday problem simulation
needle.f90584Buffon's needle problem simulation
two_die.f90585Two dice problem simulation
shielding.f90586-587Neutron shielding problem simulation
Chapter 14: Boundary Value Problems for Ordinary Differential Equations
bvp1.f90602-603Boundary value problem solved by discretization technique
bvp2.f90605-606Boundary value problem solved by shooting method
Chapter 15: Partial Differential Equations
parabolic1.f90618-619 Parabolic partial differential equation problem
parabolic2.f90620-621Parabolic PDE problem solved by Crank-Nicolson method
hyperbolic.f90633-634Hyperbolic PDE problem solved by discretization
seidel.f90642-645 Elliptic PDE solved by discretization/ Gauss-Seidel method
Chapter 16: Minimization of Functions
Chapter 17: Linear Programming

Addditional programs can be found at the textbook's anonymous ftp site:

FortranRk4 Fortran Code
[Home] [Features] [TOC] [Purchase] [Sample Code] [Web] [Manuals] [Errata] [Links]
Last updated: 5/20/2003

PROGRAM PCMET
OPEN(1,’INPUT.DAT’)
OPEN(2,’OUTPUT.DAT’)
READ(1,*)A,B,N,Y0
CALL PCM(A,B,N,Y0)
END PROGRAM

SUBROUTINE PCM(A,B,N,Y0)
F(T,Y)=Y-T*T+1
G(T)=(T+1)**2-0.5*EXP(T)
REAL::T(0:N),W(0:N),K1,K2,K3,K4
WRITE(2,*)’ADAMS 4TH ORDER PC METHOD:’
WRITE(2,10)
10 FORMAT(3X,’T’,9X,’W’,8X,’EXACT’,5X,’ERROR’)
H=(B-A)/N
T(0)=A
W(0)=Y0
WRITE(2,11)T(0),W(0),G(T(0)),ABS(W(0)-G(T(0)))
11 FORMAT(2X,F4.2,2X,F9.6,2X,F9.6,2X,F9.6)
DO I=0,2
K1=H*F(T(I),W(I))
K2=H*F(T(I)+0.5*H,W(I)+0.5*K1)
K3=H*F(T(I)+0.5*H,W(I)+0.5*K2)
K4=H*F(T(I)+H,W(I)+K3)
W(I+1)=W(I)+(K1+2*K2+2*K3+K4)/6
T(I+1)=A+(I+1)*H
WRITE(2,11)T(I+1),W(I+1),G(T(I+1)),ABS(W(I+1)-G(T(I+1)))
END DO
DO I=3,N-1
T(I+1)=A+(I+1)*H
W(I+1)=W(I)+H*(55*F(T(I),W(I))-59*F(T(I-1),W(I-1))+37*F(T(I-2),W(
1I-2))-9*F(T(I-3),W(I-3)))/24
W(I+1)=W(I)+H*(9*F(T(I+1),W(I+1))+19*F(T(I),W(I))-5*F(T(I-1),W(I-1
1))+F(T(I-2),W(I-2)))/24
WRITE(2,11)T(I+1),W(I+1),G(T(I+1)),ABS(W(I+1)-G(T(I+1)))
END DO
END SUBROUTINE Mirc torrent download.

Rk4 Fortran Code Examples

Program Description Explanation File of program below (EULROMB) NEW Solve Y'= F(X,Y) with Initial Condition Y(X0)=Y0 using the Euler-Romberg Method. Free download soft for mac.

FortranRk4 Fortran Code

Runge Kutta Fehlberg Fortran Code

Both RK2 and RK4 methods were implemented into the code as functions. The unique thing about casting RK2 and RK4 as functions, is that a program-mer can easily change the forces applicable to the problem by swapping out a single equation. Without these functions, a new piece of code must be produced for every type of force law. In the following short equivalent programs, one in Fortran and one in C, we use the 'classic' fourth-order Runge-Kutta integration algorithm to solve the one-dimensional harmonic oscillator problem. 7 For a sufficiently small Runge-Kutta timestep dt the coordinate q ( t ) and momentum approach the analytic sinusoidal solution of the two.