# Plotting a graph import matplotlib.pyplot as plt import numpy as np m = 3 #def
ID: 3846679 • Letter: #
Question
# Plotting a graph
import matplotlib.pyplot as plt
import numpy as np
m = 3 #definig m = 3 as given
j = np.arange(1, m+1) # Giving j range from 1 to m+1 equally
a = [] # list to store a0,a1,a2..a10 valuess
result = [] # list to store result of cos funcion result
sum=0 # variable to sum the value
for i in range(0,m): # Getting a0..a10 values from input
ai = input("Enter a" + str(i) + " value :- ")
a.append(ai)
for i in range (0,m): # Getting result value
value = a[i] * np.cos(2*np.pi*i*j[i]/m)
sum=sum+a[i]; # code to compute the sum
result.append(value)
print('Sum value is',sum)
plt.plot(j, result) # plotting j and f(j)
plt.xlabel('j')
plt.ylabel('f(j)')
plt.title('Graph')
plt.grid(True)
#plt.savefig("result.png")
plt.show() # showing plot
Explanation / Answer
# Plotting a graph
import matplotlib.pyplot as plt
import numpy as np
m = 3 #definig m = 3 as given
j = np.arange(1, m+1) # Giving j range from 1 to m+1 equally
a = [] # list to store a0,a1,a2..a10 valuess
result = [] # list to store result of cos funcion result
sum=0 # variable to sum the value
for i in range(0,m): # Getting a0..a10 values from input
ai = input("Enter a" + str(i) + " value :- ")
a.append(ai)
for i in range (0,m): # Getting result value
value = a[i] * np.cos(2*np.pi*i*j[i]/m)
sum=sum+a[i]; # code to compute the sum
result.append(value)
print('Sum value is',sum)
plt.plot(j, result) # plotting j and f(j)
plt.xlabel('j')
plt.ylabel('f(j)')
plt.title('Graph')
plt.grid(True)
#plt.savefig("result.png")
plt.show() # showing plot
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.