```1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 ``` ```; root finding (define (signum x) (if (negative? x) -1 (if (positive? x) 1 0))) (define (bisection f lo hi epsilon) (let loop ((lo lo) (f-lo (f lo)) (hi hi) (f-hi (f hi))) (let* ((mid (/ (+ lo hi) 2)) (f-mid (f mid))) (cond ((or (zero? f-mid) (< (abs (- hi lo)) epsilon)) mid) ((= (signum f-lo) (signum f-mid)) (loop mid f-mid hi f-hi)) (else (loop lo f-lo mid f-mid)))))) (define (regula-falsi f lo hi epsilon) (let loop ((lo lo) (f-lo (f lo)) (hi hi) (f-hi (f hi))) (let* ((mid (/ (- (* f-lo hi) (* f-hi lo)) (- f-lo f-hi))) (f-mid (f mid))) (cond ((or (zero? f-mid) (< (abs (- mid lo)) epsilon) (< (abs (- mid hi)) epsilon)) mid) ((= (signum f-lo) (signum f-mid)) (loop mid f-mid hi f-hi)) (else (loop lo f-lo mid f-mid)))))) (define (f x) (* (sin x) x x x)) (display (bisection f 1. 10. 1e-12)) (newline) (display (bisection f 10. 1. 1e-12)) (newline) (display (regula-falsi f 1. 10. 1e-12)) (newline) (display (regula-falsi f 10. 1. 1e-12)) (newline) ```
 ```1 2 3 4 ``` ```3.141592653589697 3.141592653589697 3.1415926535883956 3.1415926535883956 ```