Last active
February 13, 2016 04:33
-
-
Save RussellAndrewEdson/e2357cb76da7d164758c to your computer and use it in GitHub Desktop.
Plotting the bifurcation diagram for the logistic equation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; 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