-
-
Save Jach/e16afe15c556a21d87d7fbb8f05a9891 to your computer and use it in GitHub Desktop.
Graphs of bodyweight vs time, Lisp version
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
; quick and dirty adaptation from https://gist.github.com/stucchio/1403042 | |
(ql:quickload :numcl) | |
(ql:quickload :vgplot) | |
(defparameter *exercise-level* 1.5) | |
(defparameter *height-inches* (* 6 12)) | |
(defparameter *a* (/ (* *exercise-level* (+ 66 (* 12.7 *height-inches*))) | |
3500.0)) | |
(defparameter *b* (/ (* *exercise-level* 6.23) | |
3500)) | |
(defparameter *g* (/ (* *exercise-level* 6.775) | |
(* 365 3500.0))) | |
(defparameter *age-range* '(28 40)) | |
(defparameter *t* (numcl:arange (* 365 (first *age-range*)) | |
(* 365 (second *age-range*)))) | |
(defun base-weight (consumption time) | |
(numcl:/ (numcl:+ (numcl:* *b* (- (numcl:/ consumption 3500.0) *a*)) | |
(numcl:* *b* *g* time) | |
(numcl:- *g*)) | |
(numcl:* *b* *b*))) | |
(print (base-weight 3000 (* 25 365))) | |
(defun weight (time consumption initial-weight) | |
(let ((c (numcl:- initial-weight (base-weight consumption time)))) | |
(numcl:+ (base-weight consumption time) | |
(numcl:* c (numcl:exp (numcl:* (numcl:- *b*) (numcl:- time (aref time 0)))))))) | |
(vgplot:plot *t* (base-weight 3500 *t*) "Perfect Balance, 3500 cals" | |
*t* (base-weight 3000 *t*) "Perfect Balance, 3000 cals" | |
*t* (weight *t* 3500 (base-weight 3000 *t*)) "Paula Deen Fan" | |
*t* (weight *t* 3000 (base-weight 3000 *t*)) "Alton Brown Fan" | |
) | |
(defun xticks (tick-locations labels) | |
(let ((xtics-data (mapcar (lambda (label location) | |
(uiop:strcat "\"" (write-to-string label) "\" " (write-to-string location))) | |
(coerce labels 'list) | |
(coerce tick-locations 'list)))) | |
(vgplot:format-plot nil "set xtics (~{~a~^, ~})" xtics-data) | |
(vgplot:replot))) | |
(let ((age-years (numcl:arange (first *age-range*) (1+ (second *age-range*))))) | |
(xticks (numcl:* 365 age-years) | |
age-years)) | |
(vgplot:xlabel "Age (years)") | |
(vgplot:ylabel "Bodyweight (lbs)") | |
(vgplot:axis `(nil ,(* 365 (second *age-range*)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See also https://www.chrisstucchio.com/blog/2011/weight_stability.html for explanation