当前位置: 首页 > 工具软件 > mp-Math > 使用案例 >

math 内置函数 和 numpy内置函数的区别

宓英哲
2023-12-01

这个 好像没什么好些的,但是还是记录下来吧   直接来代码 

t = np.linspace(0, 2*np.pi, 100)
x = (16 * np.sin(t) ** 3)/1.5
y = (13 * np.cos(t) - 5 * np.cos(2*t) - 2 * np.cos(3*t) - np.cos(4*t))/1.5
plt.plot(x, y, 'r-', linewidth=2)
#plt.fill(x, y,'red')
m = (16 * np.sin(t) ** 3)/2-13
n = (13 * np.cos(t) - 7 * np.cos(2*t) - 1* np.cos(3*t) - np.cos(4*t))/2
plt.plot(m, n, 'red', linewidth=2)
plt.fill(m, n,'red')#'#DC143C' '#FF1493'  'darkred''#8B0000','firebrick':'#B22222',
a=np.arange(-30,20)
b=0.5*a+4
plt.plot(a,b,'red', linewidth=3)
plt.fill(x, y,'red')
c=np.arange(19,21)
d=-2*c+52.8
plt.plot(c,d,'red', linewidth=3)
plt.fill(x, y,'red')

p=np.arange(-30,-26)
q=p*0-11
plt.plot(p,q,'red', linewidth=3)

r=np.arange(-11,-8)
s=r*0-30
plt.plot(s,r,'red', linewidth=3)
plt.grid(True)
plt.show()

这段代码就是画心形线,当然略有不同。

t = np.linspace(0, 2*np.pi, 100)
x = (16 * np.sin(t) ** 3)/1.5
y = (13 * np.cos(t) - 5 * np.cos(2*t) - 2 * np.cos(3*t) - np.cos(4*t))/1.5

这样的t = np.linspace(0, 2*np.pi, 100)可以换成t = np.linspace(0, 2*math.pi, 100)  但是下面的就不可以换成x = (16 * math.sin(t) ** 3)/1.5 。

好吧 仔细一想当然不同了 。用numpy的时候 还是用 np里的函数吧 。

 

 类似资料: