lizfcm/deprecated-cl/approx,derivative.lisp

26 lines
660 B
Common Lisp
Raw Permalink Normal View History

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
(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))))
(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))))