2010年11月6日土曜日

diffint, diffint1

file: comm2.lisp
diff(integrate(f(s,x),s,t,x),x)を計算する過程で呼ばれる。
不定積分=>
定積分=> 積分と微分の交換、積分範囲で微分
(defmfun diffint (e x) ;; example ((%INTEGRATE . #1=(SIMP)) (($F . #1#) $S) $S 0 $T) $X
  (let (a)
    (cond 
      ;;indefinite integral
      ((null (cdddr e)) 
           (cond ((alike1 x (caddr e)) (cadr e))
             ((and (not (atom (caddr e))) (atom x) (not (free (caddr e) x)))
              (mul2 (cadr e) (sdiff (caddr e) x)))
             ((or ($constantp (setq a (sdiff (cadr e) x)))
                  (and (atom (caddr e)) (free a (caddr e))))
              (mul2 a (caddr e)))
             (t (simplifya (list '(%integrate) a (caddr e)) t))))
      ;;definite integral
      ;;integrating variable = differential variable 
      ((alike1 x (caddr e)) (addn (diffint1 (cdr e) x x) t))
      ;;integrating variable =/ differential variable 
      (t (print (simplifya (list 'b) t)))
      (t (addn (cons 
                     ;; differentiate integrand with respect to x
                     (if (equal (setq a (sdiff (cadr e) x)) 0)
                         0
                         ;; integrate a 
                         (simplifya (list '(%integrate) a (caddr e) (cadddr e) (car (cddddr e))) t))
                     ;; arguments are (integrand, integrating variable, integral range), differential variable, integrating variable
                     (diffint1 (cdr e) x (caddr e))) t)))))


(defun diffint1 (e x y)
  (let ((u (sdiff (cadddr e) x)) (v (sdiff (caddr e) x)))
    ;;int_(caddr e)^(cadddr e) (car e)(y) dy
    ;;(mul2 'a 'b) => '((%mtimes) a b)
    (list (if (pzerop u) 0 (mul2 u (maxima-substitute (cadddr e) y (car e))))
   (if (pzerop v) 0 (mul3 v (maxima-substitute (caddr e) y (car e)) -1)))))

0 件のコメント:

コメントを投稿