我目前有三个正弦函数(y1、y2、y3),并且希望在新函数(ytotal)中对函数的输出求和,但仅限于正弦函数的输出大于 0 的情况。
import numpy as np
import matplotlib.pyplot as plt
#%%
phi = np.linspace(-2*np.pi, 2*np.pi, 100)
y1 = 0.2*np.sin(phi)
y2 = 0.2*np.sin(phi-(120*(np.pi/180)))
y3 = 0.2*np.sin(phi-(240*(np.pi/180)))
#if y1 or y2 or y3 > 0:
# ytotal = y1+y2+y3
plt.plot(phi,y1, label = "Piston 1")
plt.plot(phi,y2, label = "Piston 2")
plt.plot(phi,y3, label = "Piston 3")
#plt.plot(phi,ytotal, label = "Total output")
positions = (0,np.pi/3,2*np.pi/3,np.pi,4*np.pi/3,5*np.pi/3,2*np.pi)
labels = ("0","60","120","180","240","300","360")
plt.xticks(positions, labels)
plt.xlabel('Angular displacement')
plt.ylabel('Stroke')
plt.legend()
plt.show()
输出应类似于以下内容:
30秒到达战场
相关分类