Added TaylorSin, the Taylor polynomial of sine of degree n
This commit is contained in:
parent
5095d55cdb
commit
b14afb1fa5
|
@ -799,6 +799,7 @@
|
||||||
Sin Cos Tan Sqrt
|
Sin Cos Tan Sqrt
|
||||||
Solve-quadratic
|
Solve-quadratic
|
||||||
Solve-linear
|
Solve-linear
|
||||||
|
TaylorSin
|
||||||
List->Set
|
List->Set
|
||||||
Define
|
Define
|
||||||
Range
|
Range
|
||||||
|
@ -1143,6 +1144,20 @@
|
||||||
(List (Minus (Quotient b a)))
|
(List (Minus (Quotient b a)))
|
||||||
(List)))
|
(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
|
(define Range
|
||||||
; 0-based when only given imax
|
; 0-based when only given imax
|
||||||
(case-lambda
|
(case-lambda
|
||||||
|
|
Loading…
Reference in New Issue
Block a user