# Python使用集成绘制函数

import matplotlib.pyplot as plt

from scipy import integrate

import numpy as np

def g(t):

``````g_value= integrate.quad (t,0,t)
``````
``````return (g_value)
``````

def f(t):

``````f_value = t**3 - g(t)

return (f_value)
``````

t1 = np.arange (-5, 5, 0.1)

plt.figure(1)

plt.subplot(211)

plt.plot(t1, f(t1))

plt.show()

1 条回答

• import numpy as np

def g(t):

``````g_value= integrate.quad (lambda t: t, 0, t)
return (g_value)
``````

def f(t):

``````f_value = t**3 - g(t)
return (f_value)
``````

t1 = np.arange (-5, 5, 0.1)
ft1 = []
for tt in t1:

``````ft1.append(f(tt)[0])
``````

plt.figure(1)
plt.subplot(211)
plt.plot(t1, ft1)
plt.show()
矢量化版本可以像这样完成
import numpy as np
def g(t):

``````g_value= integrate.quad (lambda t: t ,0,t)
return (g_value)
``````

g_vectorized = np.vectorize(g)

def f(t):

``````f_value = t**3 - g_vectorized(t)
return (f_value)
``````

t1 = np.arange (-5, 5, 0.1)

plt.figure(1)
plt.subplot(211)
plt.plot(t1, f(t1)[0])
plt.show()

2019-07-17 23:29:43
赞同 展开评论 打赏

31
1
0
19
1
0
21
4
0
22
2
0
26
1
0
27
1
0
69
3
0
114
1
0
233
2
0
619
2
0

## 相关电子书

From Python Scikit-Learn to Sc 立即下载
Data Pre-Processing in Python: 立即下载