All problems
Fourier Series Square Wave Value
Problem
The square wave of amplitude 1 has the Fourier series (4/pi) * sum over odd k of sin(k*x) / k.
Evaluate the partial sum including all odd k from 1 through n at the point x (radians). Near the jump the partial sum overshoots (the Gibbs phenomenon).
Hint
Iterate k = 1, 3, 5, ... up to n and accumulate sin(k x) / k.
Test cases
case 1
in: [0,99]
expected: 0
case 2
in: [1.5707963267948966,99]
expected: 0.9936344385781744
case 3
in: [0.5235987755982988,9]
expected: 0.9559401661265586
case 4
in: [3.141592653589793,99]
expected: 0
Starter codePython
def square_wave_value(x, n):
# Your code here
pass4 test cases · run your code against them in the editor