Write a function that takes five inputs: a minimum x value, a maximum x value, a
ID: 3868253 • Letter: W
Question
Write a function that takes five inputs: a minimum x value, a maximum x value, and three frequencies. It should not return any outputs. Instead, it should create a plot the sine function of each frequency, as in sin(2*pi* frequency*x), for 200 evenly spaced x values between the minimum x value and the maximum x value. All three plots should be on the same axes. Your plot should have a title and a legend. You can use the linspace function, and any of the functions related to plot to write this function.Explanation / Answer
import matplotlib.pyplot as plt
from math import sin, cos, pi
from numpy import linspace
x_min = int(input('Enter minimum'))
x_max = int(input('Enter maximum'))
freq = input('Enter frequencies (space seprated)').strip().split()
freq = list(map(int,freq))
x = linspace(x_min,x_max,200)
y = []
for i in freq:
y.append([sin(2*pi*i*t) for t in x])
plt.figure(figsize=(10, 5))
plt.title('Sine')
plt.xlabel('t (radians)')
plt.ylabel('red: sin one (t), blue: sin two (t), green: sin three (t)')
plt.grid(True)
plt.xlim(0,2*pi)
plt.ylim(-1.1,1.1)
plt.plot(x, y[0], color="red", label="sine freq 1")
plt.plot(x, y[1], color="blue", label="sine freq 2")
plt.plot(x, y[2], color="green", label="sine freq 3")
plt.legend()
plt.show()
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.