python如何使用三角函数_python中三角函数的积分

这可能是您想要的:

{1美元^import numpy as np

import matplotlib.pyplot as plt

from scipy import integrate

# 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()

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值