From 874edf17f22158954c3c4c477310d3b216f45a31 Mon Sep 17 00:00:00 2001 From: Camden Dixie O'Brien Date: Fri, 1 Jan 2021 00:00:39 +0000 Subject: [PATCH] Implement hamiltonian simulation --- Main.hs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Main.hs b/Main.hs index 01623ba..050a65d 100644 --- a/Main.hs +++ b/Main.hs @@ -32,5 +32,23 @@ rod = color rodColor $ line [ (0, 0), (0, negate rodLength) ] particle = color particleColor $ circleSolid particleRadius rotateRadians = rotate . radToDeg . negate +step _ _ = nextState +nextState state = State (theta state + thetaDot state) + (pTheta state + pThetaDot state) + (phi state + phiDot state) + (pPhi state + pPhiDot state) +thetaDot state + = (6 * (2 * pTheta state - 3 * cos (theta state - phi state) * pPhi state)) + / (particleMass * rodLength ^ 2 * (16 - 9 * cos (theta state - phi state) ^ 2)) +phiDot state + = (6 * (8 * pPhi state - 3 * cos (theta state - phi state) * pTheta state)) + / (particleMass * rodLength ^ 2 * (16 - 9 * cos (theta state - phi state) ^ 2)) +pThetaDot state + = (- 1 / 2) * particleMass * rodLength ^ 2 + * (thetaDot state * phiDot state * sin (theta state - phi state) + 3 * g * sin (theta state) / rodLength) +pPhiDot state + = (1 / 2) * particleMass * rodLength ^ 2 + * (thetaDot state * phiDot state * sin (theta state - phi state) - g * sin (phi state) / rodLength) + window = InWindow "Double Pendulum" (800, 800) (100, 100) -main = display window white (render initialState) +main = simulate window white framesPerSecond initialState render step