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

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...
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”.
(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...
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.)
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...
Python code def overlap(user1, user2, interests): """ Return the number of interests that user1 and user2...
Python code def overlap(user1, user2, interests): """ Return the number of interests that user1 and user2 have in common """ return 0    def most_similar(user, interests): """ Determine the name of user who is most similar to the input user defined by having the most interests in common. Return a tuple: (most_similar_user, num_interests_in_common) """ return ("", 0)    def recommendations(user, interests): """ Find the user who shares the most interests with the specified user. Recommend to user any interests that...
In Python write a function with prototype “def dictsort(d):” which will return a list of key-value...
In Python write a function with prototype “def dictsort(d):” which will return a list of key-value pairs of the dictionary as tuples (key, value), reverse sorted by value (highest first) and where multiple keys with the same value appear alphabetically (lowest first).
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT