Skip to content

Instantly share code, notes, and snippets.

@Jach
Forked from stucchio/gist:1403042
Last active June 8, 2021 05:54
Show Gist options
  • Save Jach/e16afe15c556a21d87d7fbb8f05a9891 to your computer and use it in GitHub Desktop.
Save Jach/e16afe15c556a21d87d7fbb8f05a9891 to your computer and use it in GitHub Desktop.
Graphs of bodyweight vs time, Lisp version
; 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*))))
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Jach
Copy link
Author

Jach commented Jun 8, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment