Skip to content

Instantly share code, notes, and snippets.

@kballenegger
Created March 3, 2012 01:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kballenegger/43d40ee5e9b12619ca1b to your computer and use it in GitHub Desktop.
Save kballenegger/43d40ee5e9b12619ca1b to your computer and use it in GitHub Desktop.
(defn round-magnitude [d m]
(/ (round (* d m)) m))
(defn derivative [precision-magnitude f]
(let [dx (expt 10 (- 0 precision-magnitude 1))]
#(let [d (/ (- (f (+ % dx)) (f %)) dx)]
(round-magnitude d precision-magnitude))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment