Skip to content
DeepForgeby svx
All problems
HardTime Seriests-296

Harmonic Regression Fit Value

Problem

Evaluate a fitted harmonic regression at time index t. The coefficient list is [a0, a1, b1, a2, b2, ...] and the fitted value is a0 + sum over k of a_k * cos(2*pi*k*t / period) + b_k * sin(2*pi*k*t / period).

Return 0.0 when period is not positive or the coefficient list is empty.

Hint

Coefficients come in (cosine, sine) pairs, one pair per harmonic.

Test cases

case 1
in: [[10,2,0],4,0]
expected: 12
case 2
in: [[10,2,0],4,1]
expected: 10
case 3
in: [[10,2,0],4,2]
expected: 8
case 4
in: [[5,1,1,0.5,0],8,2]
expected: 5.5
case 5
in: [[],4,1]
expected: 0
Starter codePython
import math
def harmonic_regression_fit(coeffs, period, t):
    # Your code here
    pass

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