Skip to content
DeepForgeby svx
All problems
EasyCalculusca-103

Chebyshev Polynomial Value

Problem

Evaluate the Chebyshev polynomial of the first kind T_n(x) with the recurrence:

T_0 = 1, T_1 = x, T_{k+1} = 2 * x * T_k - T_{k-1}

Assume n >= 0.

Hint

On [-1, 1] this equals cos(n * arccos(x)), and T_n(-1) = (-1)^n.

Test cases

case 1
in: [0,0.3]
expected: 1
case 2
in: [2,0.5]
expected: -0.5
case 3
in: [3,0]
expected: 0
case 4
in: [4,1]
expected: 1
case 5
in: [5,-1]
expected: -1
Starter codePython
def chebyshev_t(n, x):
    # Your code here
    pass

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