3 ms·
You can also approximate a cosine with a polynomial https://wordsandbuttons.online/sympy_makes_math_fun_again.html https://wordsandbuttons.online/sympy_makes_ma
by okaleniuk 6y ago
You can also approximate a cosine with a polynomial https://wordsandbuttons.online/sympy_makes_math_fun_again.html https://wordsandbuttons.online/sympy_makes_math_fun_again.ht...
This works fast, doesn't use the cache, and performs reasonably well precision-wise. It also has very small error in +/-PI/2 so, unlike with the Taylor's series, the continuation is virtually seamless.
Moreover, since cosine is symmetrical, you can throw away the even coefficients completely and it will become even faster.
- azhenley 6y agoI hadn’t read about this. It looks promising, thank you!
- Someone 6y agoThe truncated Taylor series is a polynomial, too, and also even, but has the disadvantage that it doesn’t distribute the error evenly (it’s zero at zero, but in general larger than that of the polynomial that optimizes for minimizing the maximum error over the interval of interest) You may want to optimize for something else than minimizing the maximum error, though, as it may have glaring errors. For example, for sin(x), it feels worse to have sin(0) not be exactly equal to zero than to have sin(π/4) not be exactly equal to ½√2. It may be hard to come up with a good better optimization criterion, though, and it may be easier to avoid ‘howler’ errors by making your approximation good enough.