This file contains 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))) |
This file contains 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 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 |
This file contains 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
;;; 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. |
This file contains 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
;;; The logistic equation, x(n+1) = r*x(n)*(1-x(n)) | |
(define (logistic-equation r x) | |
(* r x (- 1 x))) |
This file contains 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
;;;; Racket code to explore the chaotic behaviour of the logistic equation. | |
;;;; Date: 13/02/2016 | |
#lang racket | |
(require plot) | |
;;; The logistic equation, x(n+1) = r*x(n)*(1-x(n)) | |
(define (logistic-equation r x) | |
(* r x (- 1 x))) |
This file contains 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
;;;; Scheme code to plot the chaotic behaviour of the Lorenz attractor. | |
;;;; Date: 09/01/2016 | |
#lang racket | |
(require plot) | |
;;; The parameters for the attractor (these values were used by Lorenz to | |
;;; demonstrate the chaotic behaviour. | |
(define rho 28) | |
(define sigma 10) |
This file contains 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
;;; Code for the Simulated Annealing Cryptanalysis example. | |
;;; | |
;;; Code Author: Russell Edson | |
;;; Date: 28/05/2015 | |
;; The letters for the key alphabet (ie. A-Z.) | |
(defconstant +key-alphabet+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ") | |
;; Letter frequencies (from "Cryptological Mathematics", R.E. Lewand 2000) | |
(defconstant +english-letter-frequencies+ |
This file contains 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
(defn g | |
"The recursive G function from Godel, Escher, Bach: takes | |
in an integer n and returns G(n) = n - G(G(n-1)), with G(0) = 0." | |
[n] | |
(if (= n 0) | |
0 | |
(- n (g (g (- n 1)))))) |
This file contains 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
(declare f m) | |
(defn f | |
"The F function from Godel, Escher, Bach: takes in | |
an integer n and returns F(n) = n - M(F(n-1)), with F(0) = 1." | |
[n] | |
(if (= n 0) | |
1 | |
(- n (m (f (- n 1)))))) |
This file contains 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
(defn h | |
"The recursive H function from Godel, Escher, Bach: takes | |
in an integer n and returns H(n) = n - H(H(H(n-1))), with H(0) = 0." | |
[n] | |
(if (= n 0) | |
0 | |
(- n (h (h (h (- n 1))))))) |
NewerOlder