I am trying to write a Taylor series in F #. See my code
let rec iter abfi = if a > b then i; else fa (iter (a+1) bfi) let sum ab = iter ab (+) 0 // from 0 // e^x = 1 + x + (x^2)/2 + ... (x^n)/n! + ... let fact n = iter 1 n (*) 1 // factorial let pow xn = iter 1 n (fun n acc -> acc * x) 1 let exp x = iter 0 x (fun n acc -> acc + (pow xn) / float (fact n)) 0
On the last line, I'm trying to use int fact n for a float, but it looks like I'm wrong because this code is not compiling :( Am I doing the right algorithm?
Can I name my code first?
source share