In: Computer Science
python
def create_fourier_dataset(x, max_val=7):
"""
Return the sum of sin(n*x)/n where n = 1,2,3,4,5... max_val
Remember, n is a scalar quantity (float/int). x is a NumPy array and you should return an equal length NumPy array
:param x: numpy array
:param max_val: The maximum value
:return: a tuple with two numpy arrays x and the sum
"""
Code to copy along with screenshots of code and
output are provided.
If you have any doubts or issues. Feel free to ask in
comments
Please give this answer a like, or upvote. This will be very
helpful for me.
================================================================
Screenshots of Code :


Screenshots of Output :

Code to copy:
# importing numpy
import numpy as np
# the function asked in question
def create_fourier_dataset(x, max_val = 7):
# initialising list to store the sums
sum = []
# iterating through every element in array 'x'
for i in x:
# initialising variable to '0'
s = 0
# calculating the value
for n in range(1, max_val+1):
s = s + (np.sin(n*i))/n
# adding value to array
sum.append(s)
# creating numpy array : sum
sum = np.array(sum)
# creating tuple of two numpy arrays : x and sum
result = (x, sum)
# returning tuple
return result
# testing the function
x = np.array([1, 2, 3, 4, 5])
result = create_fourier_dataset(x)
print(result)
=========================================================