qualitative.scm 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. ;;; Homoclinic tangles
  21. (define* ((unstable-manifold T xe ye dx dy A eps) param)
  22. (let ((n (floor->exact (/ (log (/ param eps)) (log A)))))
  23. ((iterated-map T n) (+ xe (* dx (/ param (expt A n))))
  24. (+ ye (* dy (/ param (expt A n))))
  25. cons
  26. (lambda ()
  27. (error "Failed")))))
  28. (define (fixed-point-eigen T xe ye eps cont)
  29. (let ((M00 ((richardson-derivative
  30. (lambda (dx)
  31. (T (+ xe dx) ye
  32. (lambda (x y)
  33. ((principal-value pi) (- x xe)))
  34. 'failure))
  35. eps)
  36. 0.0))
  37. (M01 ((richardson-derivative
  38. (lambda (dx)
  39. (T xe (+ ye dx)
  40. (lambda (x y)
  41. ((principal-value pi) (- x xe)))
  42. 'failure))
  43. eps)
  44. 0.0))
  45. (M10 ((richardson-derivative
  46. (lambda (dx)
  47. (T (+ xe dx) ye
  48. (lambda (x y) y)
  49. 'failure))
  50. eps)
  51. 0.0))
  52. (M11 ((richardson-derivative
  53. (lambda (dx)
  54. (T xe (+ ye dx)
  55. (lambda (x y) y)
  56. 'failure))
  57. eps)
  58. 0.0)))
  59. (let ((trace (+ M00 M11))
  60. (determinant (- (* M00 M11) (* M01 M10))))
  61. (quadratic 1. (- trace) determinant
  62. (lambda (root1 root2)
  63. (cont root1 M01 (- root1 M00)
  64. root2 M01 (- root2 M00)))))))
  65. #| in open.scm
  66. (define (plot-parametric-fill win f a b near?)
  67. (let loop ((a a) (xa (f a)) (b b) (xb (f b)))
  68. (let ((m (/ (+ a b) 2)))
  69. (let ((xm (f m)))
  70. (plot-point win (car xm) (cdr xm))
  71. (if (not (and (near? xa xm) (near? xb xm)))
  72. (begin (loop a xa m xm)
  73. (loop m xm b xb)))))))
  74. (define (cylinder-near? eps)
  75. (let ((eps2 (square eps)))
  76. (lambda (x y)
  77. (< (+ (square ((principal-value pi)
  78. (- (car x) (car y))))
  79. (square (- (cdr x) (cdr y))))
  80. eps2))))
  81. |#
  82. ;;; Poincare-Birkhoff
  83. (define (radially-mapping-points map Jmin Jmax phi eps)
  84. (bisect
  85. (lambda (J)
  86. ((principal-value pi)
  87. (- phi (map phi J (lambda (phip Jp) phip) list))))
  88. Jmin Jmax eps))
  89. ;;; See indexed/driven-pend-evolution.scm
  90. ;;; Invariant Curves
  91. (define (find-invariant-curve map rn theta0 Jmin Jmax eps)
  92. (bisect (lambda (J) (which-way? rn theta0 J map))
  93. Jmin Jmax eps))
  94. #|
  95. (define (which-way? rn theta0 J0 map)
  96. (compare-streams
  97. (position-stream theta0
  98. (orbit-stream map theta0 J0)
  99. '())
  100. (position-stream theta0
  101. (orbit-stream (circle-map rn) theta0 J0)
  102. '())
  103. 0))
  104. (define (circle-map rotation-number)
  105. (let ((delta-theta (* :2pi rotation-number)))
  106. (lambda (theta y result fail)
  107. (result ((principal-value :2pi) (+ theta delta-theta))
  108. y))))
  109. (define (orbit-stream the-map x y)
  110. (cons-stream (list x y)
  111. (the-map x y
  112. (lambda (nx ny)
  113. (orbit-stream the-map nx ny))
  114. (lambda () 'fail))))
  115. (define (position-stream cut orbit list)
  116. (insert! ((principal-value cut) (car (head orbit)))
  117. list
  118. (lambda (nlist position)
  119. (cons-stream
  120. position
  121. (position-stream cut (tail orbit) nlist)))))
  122. (define (insert! x set cont)
  123. (cond ((null? set)
  124. (cont (list x) 1))
  125. ((< x (car set))
  126. (cont (cons x set) 0))
  127. (else
  128. (let lp ((i 1) (lst set))
  129. (cond ((null? (cdr lst))
  130. (set-cdr! lst (cons x (cdr lst)))
  131. (cont set i))
  132. ((< x (cadr lst))
  133. (set-cdr! lst (cons x (cdr lst)))
  134. (cont set i))
  135. (else
  136. (lp (+ i 1) (cdr lst))))))))
  137. (define (compare-streams s1 s2 count)
  138. (if (= (head s1) (head s2))
  139. (compare-streams (tail s1) (tail s2) (+ count 1))
  140. ((principal-range count) (- (head s2) (head s1)))))
  141. (find-invariant-curve (standard-map 0.95)
  142. (- 1 (/ 1 golden-mean))
  143. 0.0
  144. 2.0
  145. 2.2
  146. 1e-5)
  147. ;Value: 2.114462280273437
  148. |#
  149. (define (which-way? rotation-number x0 y0 map)
  150. (let ((pv (principal-value (+ x0 pi))))
  151. (let lp ((n 0)
  152. (z x0) (zmin (- x0 2pi)) (zmax (+ x0 2pi))
  153. (x x0) (xmin (- x0 2pi)) (xmax (+ x0 2pi)) (y y0))
  154. (let ((nz (pv (+ z (* 2pi rotation-number)))))
  155. (map x y
  156. (lambda (nx ny)
  157. (let ((nx (pv nx)))
  158. (cond ((< x0 z zmax)
  159. (if (< x0 x xmax)
  160. (lp (+ n 1) nz zmin z nx xmin x ny)
  161. (if (> x xmax) 1 -1)))
  162. ((< zmin z x0)
  163. (if (< xmin x x0)
  164. (lp (+ n 1) nz z zmax nx x xmax ny)
  165. (if (< x xmin) -1 1)))
  166. (else
  167. (lp (+ n 1) nz zmin zmax nx xmin xmax ny)))))
  168. (lambda ()
  169. (error "Map failed" x y)))))))