Skip to content

Instantly share code, notes, and snippets.

@fieldstrength
fieldstrength / Oscillator.pde
Last active August 29, 2015 14:04
Quantum harmonic oscillator probability-density animation
int step = 10; //# of pixels between computed Psi values
int time = 0;
int d=81; // = 81 = the dimensionality of this discretized Hilbert space
float[] Psi = new float[d]; // = |<x|Psi>|^2, the probability density indexed by position representation
float[] E = new float[d]; // = <E|Psi>, i.e. the state vector in energy representation (pre-normalization)
int[][] Herm = new int[d][d]; // Herm[i][j] = jth power of ksi in ith Hermite polynomial
float[] C = new float[d]; // = factor 1/(sqrt(2^n * n!)), the normalization constant for nth Hermite polynomial
-- boilerplate functions
natToInt : Nat -> Int
natToInt Z = 0
natToInt (S n) = 1 + (natToInt n)
natToString : Nat -> String
natToString n = show (natToInt n)
@fieldstrength
fieldstrength / Sigmas.hs
Last active August 29, 2015 13:56
Higher sigma operators: basic building blocks for quantum observables
-- Sigmas Module ~ Higher Sigma operators and their operator algebra
-- Cliff Harvey
-- February 2014
module Sigmas where
import Control.Applicative
-- 4 basic complex phases: 1, -1, i, -i
data Phase = P1 | M1 | Pi | Mi deriving Eq