summaryrefslogtreecommitdiff
path: root/deprecated-cl/approx,derivative.lisp
blob: 631a5c0f409d788c94c53ee5d16a4ec06a691447 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
(in-package :lizfcm.approx)

(defun central-derivative-at (f x &optional (delta 0.01))
  (let* ((x2 (+ x delta))
         (x1 (- x delta))
         (y2 (apply f (list x2)))
         (y1 (apply f (list x1))))
    (/ (- y2 y1)
       (- x2 x1))))

(defun forward-derivative-at (f x &optional (delta 0.01))
  (let* ((x2 (+ x delta))
         (x1 x)
         (y2 (apply f (list x2)))
         (y1 (apply f (list x1))))
    (/ (- y2 y1)
       (- x2 x1))))

(defun backward-derivative-at (f x &optional (delta 0.01))
  (let* ((x2 x)
         (x1 (- x delta))
         (y2 (apply f (list x2)))
         (y1 (apply f (list x1))))
    (/ (- y2 y1)
       (- x2 x1))))