Skip to content

Instantly share code, notes, and snippets.

@liebke
Created May 30, 2009 02:07
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 liebke/120330 to your computer and use it in GitHub Desktop.
Save liebke/120330 to your computer and use it in GitHub Desktop.
;; plot a user defined function and its derivative
(use '(incanter core charts optimize))
;; define the function, x^3 + 2x^2 + 2x + 3
(defn cubic [x] (+ (* x x x) (* 2 x x) (* 2 x) 3))
;; use the derivative function to get a function
;; that approximates the derivative of cubic
(def deriv-cubic (derivative cubic))
;; plot the cubic function and its derivative
(doto (function-plot cubic -10 10)
(add-function deriv-cubic -10 10)
view)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment