(data volumes 12.2 4.9 .46 1.6) ;; volumes of the four lakes (data rates 65.2 158 175 209) ;; rates of water outflow (def ks (calc - rates / (1000 * volumes))) ;; the k's for the diffeqs (data p-levels 100 44 2 1) ;; pollution levels ;; Lake Equations: (defun f (vals) (let ( (x (first vals)) (y (second vals)) (z (third vals)) (w (fourth vals)) ) (setq xval (* (first ks) x)) (setq yval (+ (* (- (first ks)) x) (* (second ks) y))) (setq zval (+ (* (- (second ks)) y) (* (third ks) z))) (setq wval (+ (* (- (third ks)) z) (* (fourth ks) w))) (list xval yval zval wval) ) ) (defun orbits (xin yin zin win tstop numpnts) " (orbits Sin Min Ein Oin t-final numpnts) The inputs Sin, Min, Ein, and Oin are initial pollution values; t-final is the amount of time you let the system run; numpnts is the number of steps you take. ;; Examples: (orbits 10 2 2 2 10 100) ;; This means initially Superior is much dirtier than the others (10 compared ;; with 2). Time is from 0 to 10, and we're taking 100 steps (don't want to ;; overburden the computer!) (orbits 200 2 2 2 10 500) " (let ( (points (euler-nd #'f (list xin yin zin win) 0 tstop numpnts)) (xvals '()) (yvals '()) (zvals '()) (wvals '()) ) (dotimes (i (length points)) (setq xvals (append xvals (list (first (select points i))))) (setq yvals (append yvals (list (second (select points i))))) (setq zvals (append zvals (list (third (select points i))))) (setq wvals (append wvals (list (fourth (select points i))))) ) (list xvals yvals zvals wvals) (setq times (rseq 0 tstop (1+ numpnts))) (title "Superior") (range 0 (max xvals)) (plot times xvals) (title "Michigan") (range 0 (max yvals)) (plot times yvals) (title "Erie") (range 0 (max zvals)) (plot times zvals) (title "Ontario") (range 0 (max wvals)) (plot times wvals) ) )