<gh_stars>1-10
import numpy as np
from scipy.fft import dst
import matplotlib.pyplot as plt


domain  = np.linspace(0, np.pi)
display = np.linspace(-2*np.pi, 2*np.pi, 500)  # [-2pi, 2pi]
func   = np.ones_like(domain)  # Constant f(x) = 1

fig, ax = plt.subplots()
ax.plot(domain, func, 'k-')

coeffs = dst(func)

summation = 0.0
for n, a in enumerate(coeffs, 1):
    summation += a * np.sin(display*n) / domain.size
    if n in [5, 21]:
        ax.plot(display, summation, label=f'{n} Terms')

ax.legend()
plt.show()

import numpy as np
from scipy.fft import dst
import matplotlib.pyplot as plt


domain  = np.linspace(0, np.pi)
display = np.linspace(-2*np.pi, 2*np.pi, 500)  # [-2pi, 2pi]
func   = np.ones_like(domain)  # Constant f(x) = 1

fig, ax = plt.subplots()
ax.plot(domain, func, 'k-')

coeffs = dst(func)

summation = 0.0
for n, a in enumerate(coeffs, 1):
    summation += a * np.sin(display*n) / domain.size
    if n in [5, 21]:
        ax.plot(display, summation, label=f'{n} Terms')

ax.legend()
plt.show()
# [-2pi, 2pi] # Constant f(x) = 1