-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexp.rkt
34 lines (29 loc) · 839 Bytes
/
exp.rkt
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
27
28
29
30
31
32
33
34
#lang racket/base
(define (run P0 P1 n #:exp [exp exp])
(let* ((q (exp (/ (- P1 P0) n)))
(p0 (exp P0))
(p1 (for/fold ((p p0))
((i (in-range n)))
(* p q))))
(values p1 (exp P1))))
;; Evaluate approximation error for exp approximation.
(define (error P0 P1 n)
(lambda (exp)
(- (expt (exp (/ (- P1 P0) n)) n)
(/ (exp P1) (exp P0)))))
;; exp Taylor series
(define (exp-taylor order [acc 0])
(lambda (x)
(call-with-values
(lambda ()
(for/fold ((acc acc)
(xk 1)
(kfac 1))
((k (in-range (add1 order))))
(values
(+ acc (/ xk kfac))
(* xk x)
(* kfac (add1 k)))))
(lambda (acc . _) acc))))
;; Test
(define e (error +1i +.9i 100))