C CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C Program to compute basin of attraction of
C a Forced Damped Pendulum
C using 4th order Runge-Kutta Method
C A number of steps using RK4 is performed and the sign
C of angular velocity is printed on stdout
C CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
program fdp_solve
implicit none
integer P
parameter(P=1010000)
real*8 T0,TF,X10,X20
integer STEPS,PSIZE
real*8 T(P),X1(P),X2(P)
real*8 Energy
real*8 omega_0,omega,gamma,a_0,omega_02,omega2
common /params/omega_0,omega,gamma,a_0,omega_02,omega2
integer i,Nstart
real *8 PI2,PI4,PI
parameter(PI2=6.283185307179D0,PI4=2.0D0*PI2,PI=PI2/2.0D0)
omega_0 = 1.0D0
omega = 2.0D0
omega_02 = omega_0*omega_0
omega2 = omega *omega
gamma = 0.2D0
STEPS = 10000
T0 = 0.0D0
TF = 200.0D0
print *, '# Enter A and no of initial conditions:'
read(5,*) a_0, Nstart
C The Calculation:
PSIZE=P
do i = 1, Nstart
C Random initial conditions with -PI<theta<PI, -2 PI<dtheta/dt<2 PI
X10 = PI2*(rand()-0.5D0)
X20 = PI4*(rand()-0.5D0)
C X10 = PI *rand()
C X20 = PI2*rand()
call RK(T,X1,X2,T0,TF,X10,X20,STEPS,PSIZE)
if( X2(STEPS) .GT. 0.0D0)then
print *,X10,X20,1
else
print *,X10,X20,-1
endif
enddo
end
C CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C The functions f1,f2(t,x1,x2) provided by the user
C CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
real*8 function f1(t,x1,x2)
implicit none
real*8 t,x1,x2
f1=x2 !dx1/dt= v = x2
end
real*8 function f2(t,x1,x2)
implicit none
real*8 omega_0,omega,gamma,a_0,omega_02,omega2
common /params/omega_0,omega,gamma,a_0,omega_02,omega2
real*8 t,x1,x2
f2=-(omega_02+2.0D0*a_0*dcos(omega*t))*dsin(x1)-gamma*x2
end
C CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C RK(T,X1,X2,T0,TF,X10,X20,STEPS,PSIZE) is the driver
C for the Runge-Kutta integration routine RKSTEP
C Input: Initial and final times T0,T1
C Initial values at t=T0 X10,X20
C Number of steps of integration STEPS
C Size of arrays T,X1,X2
C Output: real arrays T(PSIZE),X1(PSIZE),X2(PSIZE) where
C T(1) = T0 X1(1) = X10 X2(1) = X20
C X1(i) = X1(at t=T(i)) X2(i) = X2(at t=T(i))
C T(STEPS+1)=TF
C Therefore we must have PSIZE>STEPS
C CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
subroutine RK(T,X1,X2,T0,TF,X10,X20,STEPS,PSIZE)
implicit none
integer STEPS,PSIZE
real*8 T(PSIZE),X1(PSIZE),X2(PSIZE),T0,TF,X10,X20
real*8 dt
real*8 TS,X1S,X2S !values of time and X1,X2 at given step
integer i
C Some checks:
if(STEPS .le. 1 )then
print *,'rk: STEPS must be >= 1'
stop
endif
if(STEPS .ge. PSIZE)then
print *,'rk: STEPS must be < ',PSIZE
stop
endif
C Initialize variables:
dt = (TF-T0)/STEPS
T (1) = T0
X1(1) = X10
X2(1) = X20
TS = T0
X1S = X10
X2S = X20
C Make RK steps: The arguments of RKSTEP are replaced with the new ones!
do i=2,STEPS+1
call RKSTEP(TS,X1S,X2S,dt)
T(i) = TS
X1(i) = X1S
X2(i) = X2S
enddo
end
C CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C Subroutine RKSTEP(t,x1,x2,dt)
C Runge-Kutta Integration routine of ODE
C dx1/dt=f1(t,x1,x2) dx2/dt=f2(t,x1,x2)
C User must supply derivative functions:
C real function f1(t,x1,x2)
C real Function f2(t,x1,x2)
C Given initial point (t,x1,x2) the routine advnaces it
C by time dt.
C Input : Inital time t and function values x1,x2
C Output: Final time t+dt and function values x1,x2
C Careful!: values of t,x1,x2 are overwritten...
C CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
subroutine RKSTEP(t,x1,x2,dt)
implicit none
real*8 t,x1,x2,dt
real*8 f1,f2
real*8 k11,k12,k13,k14,k21,k22,k23,k24
real*8 h,h2,h6,pi,pi2
parameter(pi =3.14159265358979324D0)
parameter(pi2=6.28318530717958648D0)
h=dt !h =dt, integration step
h2=0.5D0*h !h2=h/2
h6=0.166666666666666666666666D0*h !h6=h/6
k11=f1(t,x1,x2)
k21=f2(t,x1,x2)
k12=f1(t+h2,x1+h2*k11,x2+h2*k21)
k22=f2(t+h2,x1+h2*k11,x2+h2*k21)
k13=f1(t+h2,x1+h2*k12,x2+h2*k22)
k23=f2(t+h2,x1+h2*k12,x2+h2*k22)
k14=f1(t+h ,x1+h *k13,x2+h *k23)
k24=f2(t+h ,x1+h *k13,x2+h *k23)
t =t+h
x1=x1+h6*(k11+2.0D0*(k12+k13)+k14)
x2=x2+h6*(k21+2.0D0*(k22+k23)+k24)
if( x1 .gt. pi) x1 = x1 - pi2
if( x1 .lt. -pi) x1 = x1 + pi2
endRobert poop 9:14pmEve are you coming to coffee house my dear? 9:16pmRobert poop yeah mabety 9:16pmEve you should remember that night at the campis household when we were writing poetry I still can’t find that notebook… 9:18pmRobert shit cock. 9:21pmRobert can you see the diffrence ? 9:21pmEve What do you mean? 9:25pmRobert just believe for one second that life is on a beam and one way or the other of every decision of your life will decide the rest of your life each thing you do no matter how simple or small it may seem conducts the symphony of our livves and now that the second is over 9:27pmEve Well, if you think about it, it sort of is, every single choice you make can change your life in one way or another 9:27pmRobert well then why are we here now doing these things? whe could we be other places now doing other things? 9:29pmEve No, because since you are here doing something, there is no other place you should be, because I do believe that everything you do and everything that happens to you happens for a reason, whether it be punishment from you past life or from your ccurrent life, or good karma because of the things you have done. 9:32pmRobert karma is what we are talking about. it has no judgment of right or wrong. it is simlpy the for of consequence, the ever going force that moves though space an time. im comning to the coffee house> ive been coming my entire life. 9:33pmEve yay! I really like people who come to coffee house their entire life I also really like talking to you Robert, you have things to say 9:33pmRobert oh ? poop. fuck facebook. 9:34pmEve Por que? 9:34pmRobert love farmville. porque no? 9:34pmEve Je no ce pas, parle Francais 9:35pmRobert no fuck french just kiddin but i don;t speakcit 9:35pmEve I am really trying to become fluent in French, I want to spend a semester there next year. 9:35pmRobert bonjor 9:36pmEve There’s a start!





