diff options
| author | Elizabeth Hunt <elizabeth.hunt@simponic.xyz> | 2023-10-09 21:08:25 -0600 |
|---|---|---|
| committer | Elizabeth Hunt <elizabeth.hunt@simponic.xyz> | 2023-10-09 21:08:25 -0600 |
| commit | adda6869cb2a07984b48c39fcd70ee76449c353d (patch) | |
| tree | 3aff88b65292e2ab0e108781206d954a015b2e33 /src/approx | |
| parent | b35e3998333e8190bf07ade51dba30773b3a3d0b (diff) | |
| download | cmath-adda6869cb2a07984b48c39fcd70ee76449c353d.tar.gz cmath-adda6869cb2a07984b48c39fcd70ee76449c353d.zip | |
updates 10/9
Diffstat (limited to 'src/approx')
| -rw-r--r-- | src/approx/derivative.lisp | 10 | ||||
| -rw-r--r-- | src/approx/maceps.lisp | 6 | ||||
| -rw-r--r-- | src/approx/package.lisp | 3 |
3 files changed, 14 insertions, 5 deletions
diff --git a/src/approx/derivative.lisp b/src/approx/derivative.lisp index 02fcb4c..8aa171a 100644 --- a/src/approx/derivative.lisp +++ b/src/approx/derivative.lisp @@ -1,9 +1,17 @@ (in-package :lizfcm.approx) -(defun derivative-at (f x &optional (delta 0.01)) +(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)))) diff --git a/src/approx/maceps.lisp b/src/approx/maceps.lisp index debaa67..e2738e4 100644 --- a/src/approx/maceps.lisp +++ b/src/approx/maceps.lisp @@ -3,10 +3,10 @@ (defun compute-maceps (f a init) (let ((h init) (err init)) - (loop while (> err 0) + (loop collect (list a h err) do (setf h (/ h 2) err (abs (- (funcall f (+ a h)) (funcall f a)))) - when (> err 0) - collect (list a h err)))) + while (> err 0)))) + diff --git a/src/approx/package.lisp b/src/approx/package.lisp index c11eb60..67c6a90 100644 --- a/src/approx/package.lisp +++ b/src/approx/package.lisp @@ -1,5 +1,6 @@ (in-package :cl-user) (defpackage lizfcm.approx (:use :cl) - (:export :derivative-at + (:export :central-derivative-at + :fwd-derivative-at :compute-maceps)) |
