Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (define (fact n)
- (if (eq? n 0)
- 1
- (* (fact (- n 1)) n)
- )
- )
- (define (delta s y)
- (if (eq? s 0) 0)
- (if (eq? s 1)
- (- (car (cdr y)) (car y))
- (- (delta (- s 1) (cdr y))
- (delta (- s 1) y))
- )
- )
- (define (NewtonPolinomial sX sY lastX n x)
- ;; When called need increment n by 1.
- (define (compute_q q n)
- (if (eq? n 0)
- q
- (* (- q n) (compute_q q (- n 1)))
- )
- )
- ;; Main function.
- (define (NP sX sY lastX n h q i)
- (cond
- ((or (and (eq? (car sX) lastX)
- (eq? (cdr sX) '()))
- (eq? i 0)) (NP sX sY lastX n h q (+ i 1)))
- ((eq? i 1) (+ (car sY) (* q (delta i sY))))
- (#t (+ (* (/ (compute_q q (+ n 1))
- (fact (+ i 1)))
- (delta i sY))
- (NP (cdr sX) sY lastX (- n 1) h q (+ i 1))))
- )
- )
- (let*
- (
- (h (/ (- lastX (car sX)) n))
- (q (/ (- x (car sX)) h))
- )
- (NP sX sY lastX n h q 0)
- )
- )
- ;; (NewtonPolinomial sX sY lastX n)
- (define (bust csX csY currX maxX n)
- (display currX)
- (display " ")
- (display (NewtonPolinomial csX csY maxX n currX))
- (display " ")
- (cond
- ((> currX maxX) 0)
- (#t (bust csX csY (+ currX 0.2) maxX 11))
- )
- )
- (let
- (
- (sX '(1 2 3 4 5 6 7))
- (sY '(2 3 4 5 6 7 8))
- )
- (bust sX sY 0 15 11)
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement