Question

In: Computer Science

Write a function sin_x_crossings(begin, end, skip) that uses sin math function which takes begin, end and...

Write a function sin_x_crossings(begin, end, skip) that uses sin math function which takes begin, end and skip as input parameters, and returns the x-points as a Python list that crosses the x-axis (i.e., x-value that just before it crosses).

Hint: see axis-crossing lecture notes for hints.

Note: you cannot use for or while loops.

Note2: numpy has been imported as np

For example:

Test Result
import math
ans = sin_x_crossings(0, 4 * math.pi, 0.01)
for val in ans:
    print(round(val, 2))
3.14
6.28
9.42
import math
ans = sin_x_crossings(0, 2 * math.pi, 0.1)
for val in ans:
    print(round(val, 2))
3.1

Solutions

Expert Solution

Python code:

# importing the library as np
import numpy as np

# Defining the function sin_x_crossing
def sin_x_crossing(begin , end , skip):
  
# We can see value of x which crosses just before the x axis are multiple of pi
# hence we can get the ans directly
start = int(begin / np.pi)
end = int(end / np.pi)
  
x = np.linspace(start + 1 , end - 1 , end - start - 1) * np.pi
  
return x

Sample output:

import math
ans = sin_x_crossing(0 , 4 * math.pi , 0.01)

for val in ans:
print(round(val , 2))

import math
ans = sin_x_crossing(0 , 2 * math.pi , 0.1)
for val in ans:
print(round(val , 1))


Related Solutions

Write a function that takes a person’s first and last names as input and (a) uses...
Write a function that takes a person’s first and last names as input and (a) uses lists to return a list of the common letters in the first and last names (the intersection). (b) uses sets to return a set that is the intersection of the characters in the first and last names. (c) uses sets to return the set that is the symmetric difference between the first and last names. please write in python program
In R studio Write a function that takes as an input a positive integer and uses...
In R studio Write a function that takes as an input a positive integer and uses the print() function to print out all the numbers less than the input integer. (Example: for input 5, the function should print the numbers 1,2,3,4 { for input 1, the function should not print a number.) Use the lapply function, do not use any of the loop commands in your code.
Nice shirt! In Java, write a program that uses a function that takes in the user's...
Nice shirt! In Java, write a program that uses a function that takes in the user's name and prints out compliments directed to them. The program should provide a sentinel value by asking if they've had enough compliments and will continue until they type "yes". Include 3 different compliments pulled at random and BE SURE TO USE A FUNCTION/METHOD to take in the user's name. Sample output: Enter your name: John Smith John Smith, you have a great smile! Would...
Write a Python function ???????? that takes in a nonnegative semiprime number ? which is the...
Write a Python function ???????? that takes in a nonnegative semiprime number ? which is the product of two prime numbers ? and ? and returns the tuple ( ?, ? ) where ?≤? . Example: ????????(22)=(2,11) Example: ????????(3605282209)=(59447,60647) This problem has a time-out limit of 1 second and a memory limit of 1MB. The number ? in all test-cases will satisfy 4≤?≤800000000000000 For example: Test Result print(factorMe(22)) (2, 11) print(factorMe(3605282209)) (59447, 60647)
In python I want to create a singular function that takes two parameters 'head; and 'skip'....
In python I want to create a singular function that takes two parameters 'head; and 'skip'. Head is a linked list. Skip is a non negative value. If skip is zero it should return the linked list unchanged. The skip amount determines the amount to skip over. I want to change the linked list accordingly and then return the linked list with the modifications, not a list. If you have a linked list 11 -> 12 -> 18 -> 20...
In python I want to create a singular function that takes two parameters 'head; and 'skip'....
In python I want to create a singular function that takes two parameters 'head; and 'skip'. Head is a linked list. Skip is a non negative value. If skip is zero it should return head unchanged. The skip amount determines the amount to skip over. I want to change the linked list accordingly. If you have a linked list 11 -> 12 -> 18 -> 20 -> 24 -> 32 -> 38 -> 44 and skip =2, then you should...
Write c code program for the following Write a function, circle, which takes the radius of...
Write c code program for the following Write a function, circle, which takes the radius of a circle from the main function and assign the area of the circle to the variable, area, and the perimeter of the circle to the variable, perimeter. Hint: The function should have three variables as input. Since the contents of the variables are to be modified by a function, it is necessary to use pointers. Please type out the full usable program. Thank you.
IN SCHEME Write a function subtract which takes a list of numbers as a parameter and...
IN SCHEME Write a function subtract which takes a list of numbers as a parameter and returns a list of the differences. So, a list containing the second minus the first, third minus the second, etc. (subtract '(3 4 10 14 5)) '(1 6 4 -9)
Write the deleteNode() member function, which is also given in our textbook implementation. This function takes...
Write the deleteNode() member function, which is also given in our textbook implementation. This function takes a const T& as its parameter, which is the value of an item to search for and delete. Thus the first part of this function is similar to the search() function, in that you first have to perform a search to second the item. But once found, the node containing the item should be removed from the list (and you should free the memory...
Write a function myfn6 which takes as inputs vector u and value a, and output as...
Write a function myfn6 which takes as inputs vector u and value a, and output as vector w with its elements being “True, ” or “False, ”(w = [True, False, False, …, True]). Such that “True, ” means a is in u and “False, ” means a is not in u. Test your code for u = [0, -3, 1, 1, 2, 2, 6, 2] and a = 9, a = 1 and a = 2. Copy your code together...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT