From a79350dd76e54f9a05d72d81e71ae9d44437e268 Mon Sep 17 00:00:00 2001 From: Tobias Eidelpes Date: Sat, 5 Nov 2022 14:58:25 +0100 Subject: [PATCH] Add Exercise 2.12 --- chapter2.lisp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/chapter2.lisp b/chapter2.lisp index b1cf998..aa1c86c 100644 --- a/chapter2.lisp +++ b/chapter2.lisp @@ -105,3 +105,16 @@ and upper bound." a (make-interval (/ 1.0 (upper-bound b)) (/ 1.0 (lower-bound b)))))) + +;; Exercise 2.12 +(defun make-center-width (c w) + (make-interval (- c w) (+ c w))) +(defun center (i) + (/ (+ (lower-bound i) (upper-bound i) 2.0))) +(defun width (i) + (/ (- (upper-bound i) (lower-bound i) 2.0))) + +(defun make-center-percent (c p) + (make-interval (* c (- 1 (/ p 100))) + (* c (+ 1 (/ p 100))))) +