! Driven Chaotic Pendulum

! Kendric Tonn

 

 

CALL setupscreen(#1, #2, #3)

CALL initialize (#3, m, k, Ao, b, wd, x, v, t, tf, n, dt)

DO

FOR i = 1 to n

CALL calculate (m, k, Ao, b, wd, x, v, t, tf, n, dt)

CALL PlotPhase (#1, x, v)

NEXT i

CALL PlotPoincare (#2, x, v)

LOOP

END

 

! -------- external subroutines ----------

SUB setupscreen (#1, #2, #3)

LET xmax = pi

LET vmax = 4

OPEN #1: screen 0.01, 0.495, 0.01, 0.81

PRINT " Phase Space Plot"

BOX LINES 0, 1, 0, 1

SET WINDOW -xmax, xmax, -vmax, vmax

SET COLOR 246

PLOT -xmax, 0; xmax, 0

PLOT 0,-vmax; 0, vmax

SET COLOR "blue"

OPEN #2: screen .505, 0.99, 0.01, 0.81

PRINT " Poincare Plot"

BOX LINES 0, 1, 0, 1

SET WINDOW -xmax, xmax, -vmax, vmax

SET COLOR 246

PLOT -xmax, 0; xmax, 0

PLOT 0,-vmax; 0, vmax

SET COLOR "magenta"

OPEN #3: screen 0.01, 0.99, 0.82, 0.99

PRINT " Pendulum Parameters"

BOX LINES 0, 1, 0, 1

END SUB

 

SUB initialize (#3, m, k, Ao, b, wd, x, v, t, tf, n, dt)

WINDOW#3

LET m = 1

LET g = 9.8

LET L = g

LET k = g/L

LET x, xi = 1

LET v, vi = 0

LET t, ti = 0

LET tf= 500

!INPUT prompt"Driving frequency wD =": wD

!INPUT prompt "Driving Amplitude Ao =": Ao

!INPUT prompt "Drag Coefficient b =": b

LET wd = 2/3

LET Ao =1.78463

LET b = 0.5

LET T = 2*Pi/wD

LET n = 100

LET dt = T/n

PRINT "xi (rad)", "vi (rad/s)", "Ao", "wD", "b"

PRINT xi, vi, Ao, wD, b

END SUB

 

SUB calculate (m, k, Ao, b, wd, x, v, t, tf, n, dt)

DECLARE FUNCTION force

LET a =force (k, b, x, v, t, m, Ao, wd)/m

LET v = v+a*dt

LET x = x+dt*v

LET t = t+dt

IF x > pi then LET x = -2*pi + x

IF x < -pi then LET x = 2*pi + x

END SUB

 

SUB PlotPhase (#1, x, v)

WINDOW #1

PLOT x,v

END SUB

 

SUB PlotPoincare(#2, x, v)

WINDOW #2

PLOT x,v

END SUB

 

 

FUNCTION force (k, b, x, v, t, m, Ao, wd)

LET frestore = -k*sin(x)

LET fdrag = -b *v

LET fdrive = Ao*cos(wd*t)

LET force= fdrag + frestore + fdrive

END FUNCTION