From b14afb1fa57a5bc27401b182cd284a1760a9a033 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20Axel=20S=C3=B8gaard?= Date: Mon, 9 Dec 2013 23:19:04 +0100 Subject: [PATCH] Added TaylorSin, the Taylor polynomial of sine of degree n --- bracket/bracket.rkt | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/bracket/bracket.rkt b/bracket/bracket.rkt index 34ede8b82..a71dc9f54 100644 --- a/bracket/bracket.rkt +++ b/bracket/bracket.rkt @@ -799,6 +799,7 @@ Sin Cos Tan Sqrt Solve-quadratic Solve-linear + TaylorSin List->Set Define Range @@ -887,7 +888,7 @@ ; TODO: Reactivate this clause when bug in Expand is found. #;[(equal? (Expand (Minus u1 u2)) 0) true] - [else (construct 'Equal (list u1 u2))])) + [else (construct 'Equal (list u1 u2))])) (define (Expand u) ; [Cohen, Elem, p.253] @@ -1143,6 +1144,20 @@ (List (Minus (Quotient b a))) (List))) + (define (TaylorSin x a n) + (define (fact m) (if (zero? m) 1 (* m (fact (- m 1))))) + (define (dSin i a) ; nth deriviative of sin in a + (case (remainder i 4) + [(0) (Sin a)] [(1) (Cos a)] [(2) (Minus (Sin a))] [(3) (Minus (Cos a))])) + + ; The Taylor of polynomial of sin of degree n in the variable x + ; f(x) ~ f(a) + f'(a)/1!*(x-a) + f''(a)/2!*(x-a)^2 + ... + ; sin(x) ~ x - x^3/3! + x^5/5! - x^7/7! + ... + (define x-a (Minus x a)) + (apply Plus (for/list ([i (in-range 1 (+ n 1) 2)]) + (Times (Quotient (dSin i a) (fact i)) + (Power x-a i))))) + (define Range ; 0-based when only given imax (case-lambda