我想用我t=np.arange(0,0.99,0.01)的,x=2*cos(2*pi*12*t)但我無法得到它。我不確定,但我認為當我想一個一個地訪問t陣列的成員時,這個問題是呼叫錯誤。我該如何解決我的問題?
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)
uj5u.com熱心網友回復:
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()

uj5u.com熱心網友回復:
對您的匯入部分稍作修改:
from math import pi
from numpy import cos
import numpy as np
import matplotlib.pyplot as plt
并繪制x與m:
t=np.arange(0,0.99,0.01)
m=2*pi*12*t
x=2*cos(m)
plt.plot(m, x, 'b--o')
plt.xlabel('x')
plt.ylabel('m')
輸出:

請注意,所有x、t和m現在都是具有 (99,) 形狀的陣列,您可以從以下位置獲得:
x.shape
m.shape
t.shape
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/518100.html
標籤:Python麻木的
