0% found this document useful (0 votes)
50 views1 page

File: /home/himanshu/fortran/project1r.f95 Page 1 of 1: !print, Y0

This program uses the Runge-Kutta method of order 4 (RK4) to numerically solve a system of differential equations modeling a pendulum over time. It initializes the pendulum angle and velocity, sets the time step and total time, and then iteratively calculates the k coefficients to update the position and velocity at each step, writing the results to a file. A function f defines the right hand side of the differential equations based on the pendulum angle, gravity, and length.

Uploaded by

Himanshu Gaur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views1 page

File: /home/himanshu/fortran/project1r.f95 Page 1 of 1: !print, Y0

This program uses the Runge-Kutta method of order 4 (RK4) to numerically solve a system of differential equations modeling a pendulum over time. It initializes the pendulum angle and velocity, sets the time step and total time, and then iteratively calculates the k coefficients to update the position and velocity at each step, writing the results to a file. A function f defines the right hand side of the differential equations based on the pendulum angle, gravity, and length.

Uploaded by

Himanshu Gaur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

File: /home/himanshu/fortran/project1r.

f95 Page 1 of 1

program rk4

real y1,y2,g,l,h
real k11,k21,k31,k41,k12,k22,k32,k42,t
integer i,k
y1=3.1415926/6
!print*, y0
y2=0
h=0.0001
t=0
g=9.8
l=1
k=10/h
i=0
do while(i<k)
write(2,*) t,y1
k11=h*(y2)
k12=h*f(y1,g,l)
k21=h*(y2+k12/2)
k22=h*f(y1+k11/2,g,l)
k31=h*(y2+k22/2)
k32=h*f(y1+k21/2,g,l)
k41=h*(y2)
k42=h*f(y1+k31,g,l)
y2=y2+(k12+2*k22+2*k32+k42)/6
y1=y1+(k11+2*k21+2*k31+k41)/6
i=i+1
t=t+h
end do

end program

function f(y1,g,l)
real y1,f,g,l
f=-sin(y1)*g/l
end function

You might also like