Skip to content

Instantly share code, notes, and snippets.

@RussellAndrewEdson
Last active February 13, 2016 04:32
Show Gist options
  • Save RussellAndrewEdson/8d049b8bb73f15e92811 to your computer and use it in GitHub Desktop.
Save RussellAndrewEdson/8d049b8bb73f15e92811 to your computer and use it in GitHub Desktop.
Plotting the cobweb diagram for the logistic equation.
;;; Plots the cobweb diagram for the given number of steps, parameter r
;;; and starting point x-init.
(define (plot-cobweb-diagram steps r x-init)
(define (cobweb)
(let ((endpoints (list (vector x-init 0)))
(x x-init)
(y '()))
(for ((i (in-range 0 steps)))
(set! y (logistic-equation r x))
(set! endpoints
(cons (vector y y)
(cons (vector x y) endpoints)))
(set! x y))
(reverse endpoints)))
(parameterize ((plot-width 400)
(plot-height 400)
(plot-font-size 11)
(plot-x-label "x")
(plot-y-label "y")
(line-color 'black))
(plot
(list
(function (lambda (x) (logistic-equation r x)) 0 1)
(function identity 0 1)
(lines (cobweb)
#:x-min 0 #:x-max 1 #:color 'blue)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment