Skip to content

Instantly share code, notes, and snippets.

View RussellAndrewEdson's full-sized avatar

Russell Andrew Edson RussellAndrewEdson

  • Adelaide, Australia
View GitHub Profile
@RussellAndrewEdson
RussellAndrewEdson / logistic_equation_4.rkt
Last active February 13, 2016 04:33
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)))
@RussellAndrewEdson
RussellAndrewEdson / logistic_equation_3.rkt
Last active February 13, 2016 04:32
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
@RussellAndrewEdson
RussellAndrewEdson / logistic_equation_2.rkt
Last active February 13, 2016 04:31
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.
@RussellAndrewEdson
RussellAndrewEdson / logistic_equation_1.rkt
Created January 23, 2016 07:11
The logistic equation function definition.
;;; The logistic equation, x(n+1) = r*x(n)*(1-x(n))
(define (logistic-equation r x)
(* r x (- 1 x)))
@RussellAndrewEdson
RussellAndrewEdson / logistic_equation.rkt
Last active February 13, 2016 04:29
Racket code for plotting the behaviour of the logistic equation.
;;;; 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)))
@RussellAndrewEdson
RussellAndrewEdson / lorenz.rkt
Last active January 14, 2016 13:21
Scheme code for the Lorenz attractor.
;;;; 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)
@RussellAndrewEdson
RussellAndrewEdson / eg_simulated_annealing.lisp
Created May 28, 2015 09:24
Simulated annealing code for crypto example from uni.
;;; 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+
@RussellAndrewEdson
RussellAndrewEdson / recursive_g.clj
Created April 11, 2015 03:27
The recursive G function from Godel, Escher, Bach.
(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))))))
@RussellAndrewEdson
RussellAndrewEdson / recursive_fm.clj
Created April 11, 2015 01:57
The recursive F and M functions from Godel, Escher, Bach.
(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))))))
@RussellAndrewEdson
RussellAndrewEdson / recursive_h.clj
Last active August 29, 2015 14:18
The recursive H function from Godel, Escher, Bach.
(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)))))))