Question

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,...

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

    """

Solutions

Expert Solution

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)

 

=========================================================


Related Solutions

############callbacks ##def function_1( x ) : return x ** 2 ##def function_2( x ) : return...
############callbacks ##def function_1( x ) : return x ** 2 ##def function_2( x ) : return x ** 3 ##def function_3( x ) : return x ** 4 ## ###### create a list of callbacks to each of the functions ######by referencing their names ## ##callbacks = [ function_1 , function_2 , function_3 ] ## ######display a heading and the result of passing a value to each of the ######named functions: ## ##print( '\nNamed Functions:' ) ##for function in callbacks...
def annoying_factorial(n): if n == 0 or n == 1: return 1 if n == 2:...
def annoying_factorial(n): if n == 0 or n == 1: return 1 if n == 2: return 2 if n == 3: return 6 if n == 4: return 4 * annoying_factorial(3) if n == 5: return 5 * annoying_factorial(4) if n == 6: return 6 * annoying_factorial(5) else: return n * annoying_factorial(n-1) def annoying_fibonacci(n): if n==0: return 0 if n==1: return 1 if n==2: return 1 if n==3: return 2 if n==4: return annoying_fibonacci(4-1)+annoying_fibonacci(4-2) if n==5: return annoying_fibonacci(5-1)+annoying_fibonacci(5-2) if...
Evaluate the Riemann sum for f ( x ) = 0.9 x − 1.5 sin (...
Evaluate the Riemann sum for f ( x ) = 0.9 x − 1.5 sin ( 2 x ) over the interval [ 0 , 2.5 ] using five subintervals, taking the sample points to be right endpoints. step by step and answer please. can u also show me how to enter in ti 83.
Using Python def specialAverage():    Print the number of 0s and then return the average of...
Using Python def specialAverage():    Print the number of 0s and then return the average of either the positive values in the list (if the optional parameter has value 1) or the negative values in the list (if the optional parameter has value 0).    Arguments: a list of numbers : the list can contain any numeric values an integer : this integer is an optional parameter and only takes value 0 or 1, and defaults to 1 if the...
(a) Find the Riemann sum for f(x) = 4 sin(x), 0 ≤ x ≤ 3π/2, with...
(a) Find the Riemann sum for f(x) = 4 sin(x), 0 ≤ x ≤ 3π/2, with six terms, taking the sample points to be right endpoints. (Round your answers to six decimal places.) R6 = (b) Repeat part (a) with midpoints as the sample points. M6 = If m ≤ f(x) ≤ M for a ≤ x ≤ b, where m is the absolute minimum and M is the absolute maximum of f on the interval [a, b], then m(b...
Write a Python function with prototype “def anagramdictionary(wordlist):” that will return an “anagram dictionary” of the...
Write a Python function with prototype “def anagramdictionary(wordlist):” that will return an “anagram dictionary” of the given wordlist  An anagram dictionary has each word with the letters sorted alphabetically creating a “key”.
Find the linearization at x=a. f(x)=sin^7(x), a=π/4, (Use symbolic notation and fractions where needed.) Find the...
Find the linearization at x=a. f(x)=sin^7(x), a=π/4, (Use symbolic notation and fractions where needed.) Find the linearization of y=e^(√7x) at x=36. (Use symbolic notation and fractions where needed.)
###### THIS SHOULD BE IN PYTHON Calculate the sum of cubes. If the input is x,...
###### THIS SHOULD BE IN PYTHON Calculate the sum of cubes. If the input is x, the sum of cubes is equal to: 13 + 23 + ... + x3 Take input for the number of cubes to sum. No error checking is needed. Specifically, you may assume that the input is always a positive integer Here are some sample runs: Enter how many cubes to sum: 1    1    Enter how many cubes to sum: 3 36 Enter...
Where is the function ln(sin x ) defined and continuous?
Where is the function ln(sin x ) defined and continuous?
def mystery(L, x): if L==[]: return False if L[0] == x: return True L.pop(0) return mystery(L,...
def mystery(L, x): if L==[]: return False if L[0] == x: return True L.pop(0) return mystery(L, x) What is the input or length size of the function mystery? What is the final output of mystery([1,3,5,7], 0)? Explain in one sentence what mystery does? What is the smallest input that mystery can have? Does the recursive call have smaller inputs? Why? Assuming the recursive call in mystery is correct, use this assumption to explain in a few sentences why mystery is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT