26 lines
660 B
Common Lisp
26 lines
660 B
Common Lisp
(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))))
|