summaryrefslogtreecommitdiff
path: root/src/approx/derivative.lisp
blob: 8aa171ae6467f762e105eb0124c06a9accf5dc18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
(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 fwd-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))))