Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I use np.arange especially when I want to do math operations within a equation?

I want to use my t=np.arange(0,0.99,0.01) in x=2*cos(2*pi*12*t) but I’m not able to get it. I’m not sure but I think that problem is calling an error when I want to access a member of t array one by one. How can I solve my problem?

from math import pi
from numpy import cos
import numpy as np
import math
import matplotlib.pyplot as plt
t=np.arange(0,0.99,0.01)
print(t)
for i in range(0,len(t)):
  m=2*pi*12*t[i]
  x=2*cos(m)
  print(x)

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

import matplotlib.pyplot as plt
from  matplotlib.pyplot import figure
import numpy as np
import math as math

x_coordinates = []
y_coordinates = []

for t in np.arange(0,0.99,0.01):
    omega=2*math.pi*t*12
    x_coordinates.append(2*math.cos(omega))
    y_coordinates.append(t)
    
    
figure(num=None,figsize=(13,7))
plt.plot(x_coordinates, y_coordinates)
plt.legend()
plt.ylabel('Time(seconds)', fontsize=20)
plt.xlabel('Cos', fontsize=20)
plt.grid(True)
plt.show()
plt.show()

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading