Hamiltonian-evolution.scm 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #| -*-Scheme-*-
  2. Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
  3. 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
  4. 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Massachusetts
  5. Institute of Technology
  6. This file is part of MIT/GNU Scheme.
  7. MIT/GNU Scheme is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or (at
  10. your option) any later version.
  11. MIT/GNU Scheme is distributed in the hope that it will be useful, but
  12. WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. General Public License for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with MIT/GNU Scheme; if not, write to the Free Software
  17. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301,
  18. USA.
  19. |#
  20. #|
  21. (define ((T-pend m l g ys) local)
  22. (let ((t (time local))
  23. (theta (coordinate local))
  24. (thetadot (velocity local)))
  25. (let ((ysdot (D ys)))
  26. (* 1/2 m
  27. (+ (square (* l thetadot))
  28. (square (ysdot t))
  29. (* 2 (ysdot t) l (sin theta) thetadot))))))
  30. (define ((V-pend m l g ys) local)
  31. (let ((t (time local))
  32. (theta (coordinate local)))
  33. (* m g (- (ys t) (* l (cos theta))))))
  34. (define L-pend (- T-pend V-pend))
  35. (define ((periodic-drive amplitude frequency phase) t)
  36. (* amplitude (cos (+ (* frequency t) phase))))
  37. (define (L-periodically-driven-pendulum m l g a omega)
  38. (let ((ys (periodic-drive a omega 0)))
  39. (L-pend m l g ys)))
  40. (show-expression
  41. ((Lagrangian->Hamiltonian
  42. (L-periodically-driven-pendulum 'm 'l 'g 'a 'omega))
  43. (->H-state 't 'theta 'p_theta)))
  44. (+
  45. (* -1/2
  46. (expt a 2)
  47. m
  48. (expt omega 2)
  49. (expt (cos theta) 2)
  50. (expt (sin (* omega t)) 2))
  51. (* a g m (cos (* omega t)))
  52. (/ (* a omega p_theta (sin theta) (sin (* omega t))) l)
  53. (* -1 g l m (cos theta))
  54. (/ (* 1/2 (expt p_theta 2)) (* (expt l 2) m)))
  55. (define (H-pend-sysder m l g a omega)
  56. (Hamiltonian->state-derivative
  57. (Lagrangian->Hamiltonian
  58. (L-periodically-driven-pendulum m l g a omega))))
  59. ;;; for driven-pendulum-phase-space
  60. (define window (frame -pi pi -10.0 10.0))
  61. (start-gnuplot "pendulum-2x")
  62. (define ((monitor-p-theta win) state)
  63. (let ((q ((principal-value pi) (coordinate state)))
  64. (p (momentum state)))
  65. (plot-point win q p)))
  66. (let ((m 1.) ;m=1kg
  67. (l 1.) ;l=1m
  68. (g 9.8) ;g=9.8m/s$^2$
  69. (A 0.1) ;A=1/10 m
  70. (omega (* 2 (sqrt 9.8))))
  71. ((evolve H-pend-sysder m l g A omega)
  72. (up 0.0 ;t$_0$=0
  73. 1.0 ;theta$_0$=1 radian
  74. 0.0) ;thetadot$_0$=0 radians/s
  75. (monitor-p-theta window)
  76. 0.01 ;step between plotted points
  77. 100.0 ;final time
  78. 1.0e-12))
  79. (stop-gnuplot)
  80. (graphics-clear window)
  81. ;;; for driven-pend-nuniq1 and 2
  82. (let ((m 1.) ;m=1kg
  83. (l 1.) ;l=1m
  84. (g 9.8) ;g=9.8m/s$^2$
  85. (A 0.1) ;A=1/10 m
  86. (omega (* 2 (sqrt 9.8))))
  87. ((evolve H-pend-sysder m l g A omega)
  88. (up 0.0 ;t$_0$=0
  89. 1.0 ;theta$_0$=1 radian
  90. 0.0) ;thetadot$_0$=0 radians/s
  91. (monitor-p-theta window)
  92. 0.01 ;step between plotted points
  93. 10.0 ;final time
  94. 1.0e-12))
  95. (define ((monitor-pprime-theta mlA omega win) state)
  96. (let ((t (time state))
  97. (q ((principal-value pi) (coordinate state)))
  98. (p (momentum state)))
  99. (plot-point
  100. win
  101. q
  102. (+ p (* mlA omega (sin q) (sin (* omega t)))))))
  103. (let ((m 1.) ;m=1kg
  104. (l 1.) ;l=1m
  105. (g 9.8) ;g=9.8m/s$^2$
  106. (A 0.1) ;A=1/10 m
  107. (omega (* 2 (sqrt 9.8))))
  108. ((evolve H-pend-sysder m l g A omega)
  109. (up 0.0 ;t$_0$=0
  110. 1.0 ;theta$_0$=1 radian
  111. 0.0) ;thetadot$_0$=0 radians/s
  112. (monitor-pprime-theta (* m l A) omega window)
  113. 0.01 ;step between plotted points
  114. 10.0 ;final time
  115. 1.0e-12))
  116. (graphics-close window)
  117. |#