python如何使⽤三⾓函数_python中三⾓函数的积分这可能是您想要的:
{1美元^import numpy as np
import matplotlib.pyplot as plt
from scipy import integratelinspace函数python
# step Function
def jerkstep(xprime,k):
return (1 - 2*( int(xprime)%2 == 1 ) )*k
# Triangle function ( step integration)
def jerkint(x,k,ac):
return integrate.quad( jerkstep ,0, x, args =(k) )[0] + ac*x
# Integrate of triangle
def jerkintint(x,k,ac,vc):
return integrate.quad( jerkint, 0 , x , args = (1,0) )[0] + vc*x
# linearly spaced time samples (~ x axis)
t = np.linspace(2.0, 10.0, num = 100)
#optional arguments
k = 1
ac = 0
vc = 0
#output functions
jerk = np.array(t);
triangle = np.array(t);
curve = np.array(t);
# Warning : it can be long ( integration not optimized )
for indice,time in zip(range(len(t)),t): # Double indexation on t indices and t values
print "Time, in seconds : ", time
jerk[indice] = jerkstep(time,k)
print "Step function : " , jerk[indice]
triangle[indice] =jerkint(time,k,ac)
print "Step function integrate ( = triangle ) : " , triangle[indice]
curve[indice] = jerkintint(time,k,ac,vc)
print "Step function double integrate ( = triangle integrate ) : " , curve[indice]
print "\n"
# plot figure in mathplotlib
fig, axs = plt.subplots(3, 1, sharex=True, sharey=False) axs[0].plot(t, jerk, 'o-', label=str("Step Function"))
axs[1].plot(t, triangle, 'o-' , label=str("Triangle Function")) axs[2].plot(t, curve, 'o-' , label=str("Curve Function")) fig.show()
plt.show()

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。