2023-09-07 14:19:32 -04:00
|
|
|
(in-package :lizfcm.approx)
|
|
|
|
|
2023-10-09 23:08:25 -04:00
|
|
|
(defun central-derivative-at (f x &optional (delta 0.01))
|
2023-09-07 14:19:32 -04:00
|
|
|
(let* ((x2 (+ x delta))
|
|
|
|
(x1 (- x delta))
|
|
|
|
(y2 (apply f (list x2)))
|
|
|
|
(y1 (apply f (list x1))))
|
2023-09-13 11:54:12 -04:00
|
|
|
(/ (- y2 y1)
|
|
|
|
(- x2 x1))))
|
2023-10-09 23:08:25 -04:00
|
|
|
|
2023-10-09 23:37:44 -04:00
|
|
|
(defun forward-derivative-at (f x &optional (delta 0.01))
|
2023-10-09 23:08:25 -04:00
|
|
|
(let* ((x2 (+ x delta))
|
|
|
|
(x1 x)
|
|
|
|
(y2 (apply f (list x2)))
|
|
|
|
(y1 (apply f (list x1))))
|
|
|
|
(/ (- y2 y1)
|
|
|
|
(- x2 x1))))
|
2023-10-09 23:37:44 -04:00
|
|
|
|
|
|
|
(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))))
|