Hi!

I've been messing around with basic symbolic algebra lately. I've put up some of the experiments here:

    http://github.com/dharmatech/numero/tree/master

Below is a little session. The problem is example 1 from chapter 4.2 of Calculus by Gilbert Strang. This is a nice text and is available online:

    http://ocw.mit.edu/ans7870/resources/Strang/strangtext.htm

----------------------------------------------------------------------
;; 4.2 Example 1 (implicit differentiation)

;; y^5 + x y = 3

;; Find dy/dx at x = 2 and y = 1

;; Define the equation:

(define eq-1 (infix '( y(x) ^ 5 + x y(x) = 3 )))

;; Take the derivative of the whole equation:

(set! eq-2 (simplify (D eq-1 'x)))

(to-alg eq-2)

"5 * (D (y x) x) * (y x) ^ 4 + (y x) + x * (D (y x) x) = 0"

;; Let's use 'subst' to make it prettier:

(set! eq-3
      (subst eq-2
             ((D (y x) x) 'dy/dx)
             ((y x) 'y)))

(to-alg eq-3)

"5 * dy/dx * y ^ 4 + y + x * dy/dx = 0"

;; Plug in x=2 and y=1 :

(set! eq-4
      (simplify
       (subst eq-3
              (x 2)
              (y 1))))

(to-alg eq-4)

"7 * dy/dx + 1 = 0"

;; Solve for dy/dx:

(to-alg
 (simplify
  (solve-for eq-4 'dy/dx)))

"dy/dx = -1/7"
----------------------------------------------------------------------

Couple of things to point out...

All the symbolic manipulation is accomplished using Alex Shinn's 'match' macro. Thanks Alex!

In particular, I'm using the version packaged for R6RS by Derick, (xitomatl AS-match). Thanks Derick!

Some other examples:

    http://github.com/dharmatech/numero/raw/master/symbolic/examples.scm

Lastly, I'm not interested in bug reports. I am interested in patches. ;-)

Ed
--
Beautiful souls attract powerful demons

Reply via email to