Skip to content

Instantly share code, notes, and snippets.

@RussellAndrewEdson
Last active February 13, 2016 04:33
Show Gist options
  • Save RussellAndrewEdson/e2357cb76da7d164758c to your computer and use it in GitHub Desktop.
Save RussellAndrewEdson/e2357cb76da7d164758c to your computer and use it in GitHub Desktop.
Plotting the bifurcation diagram for the logistic equation.
;;; Plots the bifurcation diagram, using the given starting point
;;; x-init (using 100 iterations, and plots the values for the
;;; last 30.)
(define (plot-bifurcation-diagram x-init)
(define (steady-state-points)
(let ((points '())
(step-size 0.001)
(iterations 100)
(keep-last-points 30))
(for ((r (in-range 0 4 step-size)))
(let ((xs (list x-init)))
(for ((n (in-range 2 iterations)))
(let ((x (car xs)))
(set! xs (cons (logistic-equation r x) xs))))
(set! points
(append points (map (lambda (x) (vector r x))
(take xs keep-last-points))))))
points))
(parameterize ((plot-width 400)
(plot-height 400)
(plot-font-size 11)
(plot-x-label "r")
(plot-y-label "x"))
(plot (points (steady-state-points)
#:x-min 0 #:x-max 4 #:y-min 0 #:y-max 1
#:sym 'dot #:color 'blue))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment