Skip to content
DeepForgeby svx
All problems
EasyCalculusca-346

Taylor Cosine Series Value

Problem

The Maclaurin series of cos(x) is sum_{k>=0} (-1)^k x^(2k) / (2k)!.

Given x and the number of terms, return the partial sum.

Hint

Start from 1 at k = 0 and alternate signs with even factorials.

Test cases

case 1
in: [1,5]
expected: 0.5403025793650793
case 2
in: [0.5,3]
expected: 0.8776041666666666
case 3
in: [-2,8]
expected: -0.4161468396389032
Starter codePython
def taylor_cosine_series_value(x, terms):
    # Your code here
    pass

3 test cases · run your code against them in the editor