Skip to content

Instantly share code, notes, and snippets.

@ignacy
Created July 8, 2012 17:01
Show Gist options
  • Select an option

  • Save ignacy/3071779 to your computer and use it in GitHub Desktop.

Select an option

Save ignacy/3071779 to your computer and use it in GitHub Desktop.
bisekcja
(define (average a b)
(/ (+ a b) 2))
(define (close-enough? x y)
(< (abs (- x y)) 0.01))
(define (search f neg-point pos-point)
(let ((midpoint (average neg-point pos-point)))
(if (close-enough? neg-point pos-point)
midpoint
(let ((test-value (f midpoint)))
(cond ((positive? test-value)
(search f neg-point midpoint))
((negative? test-value)
(search f midpoint pos-point))
(else midpoint))))))
(define (half-interval-method f a b)
(let ((a-value (f a))
(b-value (f b)))
(cond ((and (negative? a-value) (positive? b-value))
(search f a b))
((and (negative? b-value) (positive? a-value))
(search f b a))
(else
(print "Wartosci funkcji nie maja przeciwnych znakow:" a b)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment