API for symbolic - Incanter 2.0 (in development)

by Bryce Nyeggen, with modifications by David Edgar Liebke

Full namespace name: incanter.symbolic

Overview

A library for performing symbolic math, a port from SICP (http://mitpress.mit.edu/sicp/).

Public Variables and Functions



deriv

macro
Usage: (deriv exp v)
       (deriv exp v degree)
Macro for symbolic differentiation. with 2 args, takes 1st degree deriv.
with 3, takes arbitrary degrees. contains all deriv rules for basic funcs.


Examples:

  (use '(incanter core symbolic))

  (deriv (+ x 3) x) ; => 1
  (deriv (* x y) x) ; => y
  (deriv (* (* x y) (+ x 3)) x) ; => (+ (* (+ x 3) y) (* x y))
  (deriv (* (* x y) (+ x 3)) y) ; => (* (+ x 3) x)

  (deriv (* x y (+ x 3)) x) ; => (+ (* y (+ x 3)) (* y x))
  (deriv (* x y (+ x 3)) y) ; => (* (+ x 3) x)

  (deriv (sin x) x) ; => (cos x)
  (deriv (cos x) x) ; => (* -1 (sin x))

  (deriv (sin (* x y)) y) ; => (* x (cos (* x y)))

  (deriv (pow x 3) x) ; => (* 3 (pow x 2))
  (deriv (** x 3) x) ; => (* 3 (pow x 2))

  (deriv (pow x 3) x 2) ; => (* 3 (* 2 x))

  (deriv (* x y (+ x 3)) x 2) ; => (+ y y)
  (deriv (* x y (+ x 3)) x 3) ; => 0

  (deriv (+ (* 3 x) (* 8 x)) x) ; => 11



  ;; NOT WORKING YET

  (deriv (/ 1 x) x) ; => (* (deriv* (* (x)) x) (* -1 (pow (* (x)) -2)))
                                        ^-- need to fix

    
    
    Source
  


deriv*

function
Usage: (deriv* exp v)
       (deriv* exp vr degree)
Main sub-function for differentiation. with 2 args, takes 1st degree deriv.
with 3, takes arbitrary degrees. contains all deriv rules for basic funcs.


Examples:

  (use '(incanter core symbolic))

  (deriv* '(+ x 3) 'x)
  (deriv* '(* x y) 'x)
  (deriv* '(* (* x y) '(+ x 3)) x)
  (deriv* '(* (* x y) (+ x 3)) 'y)

  (deriv* '(* x y (+ x 3)) 'x)
  (deriv* '(* x y (+ x 3)) 'y)

  (deriv* '(* x y (+ x 3)) 'x 2)
  (deriv* '(* x y (+ x 3)) 'x 3)

    
    
    Source
  


deriv-fn

macro
Usage: (deriv-fn [& args] expr v)
       (deriv-fn [& args] expr v degree)
Examples:
  (use '(incanter core symbolic))

  (deriv-fn [x y] (+ (* x y) x) x)

  ((deriv-fn [x y] (+ (* x y) x) x) 5 9)

  (use 'incanter.charts)
  (doto (function-plot sin -5 5)
     (add-function (deriv-fn [x] (sin x) x) -5 5)
     (add-function (deriv-fn [x] (sin x) x 2) -5 5)
     view)

  (let [f (fn [x] (pow x 2))
        df (deriv-fn [x] (pow x 2) x)]
    (doto (function-plot f -5 5)
      (add-function df -5 5)
      view))


  (let [f (fn [x] (pow x 3))
        df (deriv-fn [x] (pow x 3) x)]
    (doto (function-plot f -5 5)
      (add-function df -5 5)
      view))


  ;; NOT WORKING YET

  (let [f (fn [x] (/ 1 x ))
        df (deriv-fn [x] (/ 1 x) x)]
    (doto (function-plot f 0.5 5)
      (add-function df 0.5 5)
      view))

    
    
    Source
  


deriv-fn*

function
Usage: (deriv-fn* [& args] expr v)
       (deriv-fn* [& args] expr v degree)
Examples:
  (use '(incanter core symbolic))

  (deriv-fn* '[x y] '(+ (* x y) x) 'x)

  ((deriv-fn* '[x y] '(+ (* x y) x) 'x) 5 9)

    
    
    Source
  
Logo & site design by Tom Hickey.
Clojure auto-documentation system by Tom Faulhaber.