Last active
January 11, 2018 11:11
-
-
Save anon767/84088dbb7f6b78cbe3f34f5e794381fa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket/base | |
(define costfunction | |
(lambda (stg freisms kostenprosms x) | |
(+ (- stg ( * freisms kostenprosms)) (* kostenprosms x) ) | |
) | |
) | |
;tolerance | |
(define EPS 1e-3) | |
;f = function, a = start value 1 b = start value 2 n = iterations | |
(define (bisection f a b n) | |
(define m (/ (+ a b) 2)) | |
(if (> (* (f a) (f b)) 0) | |
"No root" | |
(if (> (abs (/ (- b a) 2)) EPS) | |
(if (< (* (f a) (f m)) 0) | |
(bisection f a m (add1 n)) | |
(bisection f m b (add1 n))) | |
m | |
))) | |
(display (bisection (lambda (x) (- (costfunction -50 200 30 x) (costfunction 10 100 3 x) )) -1000 1000 100000) ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment