Created
January 26, 2011 04:39
-
-
Save vedantk/796235 to your computer and use it in GitHub Desktop.
Taylor Polynomials: generate them in Racket
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
(require plot) | |
(define (factorial n) | |
(if (< n 2) 1 (* n (factorial (- n 1))))) | |
(define (taylor-poly func n c) | |
(define (calc-coeff dfn level) | |
(/ (dfn c) (factorial level))) | |
(define (find-coeff fn level coeffs) | |
(if (= level (+ n 1)) | |
coeffs | |
(find-coeff (derivative fn) (+ level 1) | |
(append coeffs (list (calc-coeff fn level)))))) | |
(find-coeff func 0 '())) | |
(taylor-poly sin 4 0) | |
; '(0 1.0 0.0 -0.5551115123125783 0.0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment