Skip to content

Instantly share code, notes, and snippets.

@RussellAndrewEdson
Last active February 13, 2016 04:31
Show Gist options
  • Save RussellAndrewEdson/f7551889fb5b4ed21ce5 to your computer and use it in GitHub Desktop.
Save RussellAndrewEdson/f7551889fb5b4ed21ce5 to your computer and use it in GitHub Desktop.
Plotting the graph for the logistic equation.
;;; Returns a list of iterations of the logistic equation for a given
;;; parameter r and starting point x-init.
(define (iterate-logistic-equation steps r x-init)
(let ((xs (list x-init)))
(for ((i (in-range 0 steps)))
(set! xs (cons (logistic-equation r (car xs)) xs)))
(map vector (stream->list (in-range 0 (+ 1 steps))) (reverse xs))))
;;; Plots the graph of x(n) for the given number of steps, parameter r
;;; and starting point x-init.
(define (plot-logistic-equation steps r x-init)
(parameterize ((plot-width 400)
(plot-height 200)
(plot-font-size 11)
(plot-x-label "n")
(plot-y-label "x(n)"))
(plot
(lines (iterate-logistic-equation steps r x-init)
#:y-min 0 #:y-max 1 #:color 'blue))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment