问题描述
我目前有三个正弦函数(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()