Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.


Runge-Kutta-Fehlberg (RKF45) Method

Runge-Kutta-Fehlberg (RKF45) Method

Hi, I dont understand very well the next code (its written in fortran 90). Its supposed to solve an initial value problem, but what is the initial condition, and why is h defined that way, are a and b arbitrary? Also, how can I change the code to evaluate the function from 0 to 4?

program main
real ::a=1.0, b=1.5625, x=2.0,t,h,e
integer ::n=72, i

function f(t,x)
real, intent(in) :: t, x
end function f
end interface

print *,"0",t,x
do i=1,n
call rk45(f,t,x,h,e)
print *,t,x,e
end do
end program main

subroutine rk45(f,t,x,h,e)
function f(t,x)
real, intent(in) :: t, x
end function f
end interface

real, intent(inout):: t,x,h,e
real, parameter :: c20=0.25; c21=0.25; &
c30=0.375; c31=0.09375; c32=0.28125; &
c40=0.92307692307692; &
c41=0.87938097405553; c42=-3.2771961766045; c43=3.3208921256258; &
c51=2.0324074074074; c52=-8.0; c53=7.1734892787524;&
c54=-0.20589668615984; &
c60=0.5; c61=-0.2962962962963; c62=2.0; &
c63=-1.3816764132554; c64=0.45297270955166; c65=-0.275; &
a1=0.11574074074074; a2=0; a3=0.54892787524366; &
a4=0.5353313840156; a5=-0.2; &
b1=0.11851851851852; b2=0.0; b3=0.51898635477583; &
b4=0.50613149034201; b5=-0.18; &

f1 = h*f(t,x)
f2 = h*f(t+ c20*h,x + c21*f1)
f3 = h*f(t+ c30*h,x + c31*f1 + c32*f2)
f4 = h*f(t+ c40*h,x + c41*f1 + c42*f2 + c43*f3)
f5 = h*f(t+h,x + c51*f1 + c52*f2 + c53*f3 + c54*f4)
f6 = h*f(t+ c60*h,x + c61*f1 + c62*f2 + c63*f3 + c64*f4 + c65*f5)
x5 = x + b1*f1 + b3*f3 + b4*f4 + b5*f5 + b6*f6
x = x + a1*f1 + a3*f3 + a4*f4 + a5*f5
t = t + h
e = abs(x - x5)
end subroutine rk45

function f(t,x)
real, intent(in):: t,x
f = 2.0+(x-t-1.0)**2
end function f

RE: Runge-Kutta-Fehlberg (RKF45) Method

a, b is the solution interval, where your ODE should be solved.
n is number of steps
h is the step, i.e. length of the interval [a, b] divided by number of the steps / h = = (b-a)/n /

To solve the ODE on [0, 4] you need to set
a=0, b=4,
x = your initial value in point a,
n = a reasonable number of solution steps on [0, 4]

RE: Runge-Kutta-Fehlberg (RKF45) Method

I think this code is incomplete, it doesn't contemplate the tolerance error in the RKF45 method. Does someone have a correct and better code for the RKF45 method? Would be much appreciated.

RE: Runge-Kutta-Fehlberg (RKF45) Method

I mean, if someone has the adaptative RKF45 method code.

RE: Runge-Kutta-Fehlberg (RKF45) Method

Oh, boy

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close