王剑编程网

分享专业编程知识与实战技巧

珍藏版-11款爱心的免费公布的数学方程式和可视化-python版

一,图:

1 直角坐标系(9款):

2 追加一款:直角坐标系:

3 极坐标系(1款):

二,爱心的数学方程式:

1 直角坐标系:

1.1 方程式1:Love-1

进行转换:


python代码中需要进行修改为:

x = np.linspace(-6,6,1000)
y1 = np.sqrt(36-x**2) + (2*abs(x)+x**2-6)/(3*abs(x)+x**2+2)
y2 = -np.sqrt(36-x**2) + (2*abs(x)+x**2-6)/(3*abs(x)+x**2+2)

1.2 方程式2:Love-2

进行转换:

python代码中需要进行修改为:

x=np.linspace(-1,1,1000)
#y1 = 0.6 * abs(x)**0.5 + ((1 - x**2) / 2)**0.5
y1 = 0.6 * np.sqrt(abs(x)) + np.sqrt((1 - x**2) / 2)  # 等同于上面
y2 = 0.6 * abs(x)**0.5 - ((1 - x**2) / 2)**0.5

1.3 方程式3:Love-3

python代码中需要进行修改为:

t=np.linspace(-np.pi,np.pi,1000)
x=2*(np.sin(t)-np.sin(2*t)/2)
y=2*(np.cos(t)-np.cos(t)**2)

1.4 方程式4:Love-4

python代码中需要进行修改为:

x = np.linspace(-1,1,1000)
y1 = np.sqrt(1 - x**2) + pow(np.abs(x),float(2)/float(3))
y2 = -np.sqrt(1 - x**2)+ pow(np.abs(x),float(2)/float(3))

1.5 方程式5:Love-5

python代码中需要进行修改为:

t = np.linspace(0, np.pi, 1000)
x = np.sin(t)
y = np.cos(t) + np.power(x, 2.0 / 3) 

1.6 方程式6:Love-6

python代码中需要进行修改为:

t=np.linspace(-180,180,2000)
r = np.sin(t) * (abs(np.cos(t))**0.7) / (np.sin(t) + 7 / 5) - 2 * np.sin(t) + 2
x = r*np.cos(t)
y = r*np.sin(t)

1.7 方程式7:Love-7

python代码中需要进行修改为:

t=np.linspace(-180,180,1000)
x = 16 * np.sin(t)**3
y = 13 * np.cos(t) - 5 * np.cos(2 * t) - 2 * np.cos(3 * t) - np.cos(4 * t)

1.8 方程式8:Love-8

转换:

python代码中需要进行修改为:

x1=np.linspace(-np.sqrt(17),0,1000)
y1 = -x1*8/17+np.sqrt(np.abs(225/17-225*x1**2/289))
y2 = -x1*8/17-np.sqrt(np.abs(225/17-225*x1**2/289))

x2=np.linspace(0,np.sqrt(17),1000)
y3 = x2*8/17+np.sqrt(np.abs(225/17-225*x2**2/289))
y4 = x2*8/17-np.sqrt(np.abs(225/17-225*x2**2/289))

1.9 方程式9:Love-9

python代码中需要进行修改为:

t=np.linspace(-1,1,2000)

x = np.sin(t)*np.cos(t)*np.log(abs(t))
y = abs(t)**0.3*np.sqrt(np.cos(t))

1.10 方程式10:Love-10

转换为

python代码中需要进行修改为:

x = np.linspace(-0.8877,0.8877,1000)

y1 = np.sqrt(np.abs(1 - x**2-(pow(np.abs(x),float(2)/float(3)))**2/4)) + pow(np.abs(x),float(2)/float(3))/2
y2 = -np.sqrt(np.abs(1 - x**2-(pow(np.abs(x),float(2)/float(3)))**2/4)) + pow(np.abs(x),float(2)/float(3))/2

第十张图的单独代码:Love-10(最后额外增加的)

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(-0.8877,0.8877,1000)

y1 = np.sqrt(np.abs(1 - x**2-(pow(np.abs(x),float(2)/float(3)))**2/4)) + pow(np.abs(x),float(2)/float(3))/2
y2 = -np.sqrt(np.abs(1 - x**2-(pow(np.abs(x),float(2)/float(3)))**2/4)) + pow(np.abs(x),float(2)/float(3))/2

plt.plot(x, y1,'r-')
plt.plot(x, y2,'r-')

plt.show()

=========

2 极坐标系:

爱心方程式11:Love-11

python代码中需要进行修改为:a=1,极坐标爱心代码

import numpy as np
import matplotlib.pyplot as plt

plt.title('Love-11:\nr=1-sinθ')
θ = np.linspace(0, 2 * np.pi, 1024)  

plt.axes(polar=True)    # 开启极坐标模式
plt.plot(θ, 1. - np.sin(θ), color="r")
plt.show()

三,图1:9种直角坐标系的爱心的方程式的代码:完整版

import numpy as np
import matplotlib.pyplot as plt

fig = plt.figure('Love',figsize=(20, 15))

ax1 = fig.add_subplot(3,3,1)
ax2 = fig.add_subplot(3,3,2)
ax3 = fig.add_subplot(3,3,3)
ax4 = fig.add_subplot(3,3,4)
ax5 = fig.add_subplot(3,3,5)
ax6 = fig.add_subplot(3,3,6)
ax7 = fig.add_subplot(3,3,7)
ax8 = fig.add_subplot(3,3,8)
ax9 = fig.add_subplot(3,3,9)

# 图1
ax1.set_title('Love-1:\n$(y-\\frac{2*|x|+x^2-6}{3*|x|+x^2+2})^2+x^2=36#39;)
x = np.linspace(-6,6,1000)
y1 = np.sqrt(36-x**2) + (2*abs(x)+x**2-6)/(3*abs(x)+x**2+2)
y2 = -np.sqrt(36-x**2) + (2*abs(x)+x**2-6)/(3*abs(x)+x**2+2)
ax1.plot(x, y1,'r-')
ax1.plot(x, y2,'r-')

# 图二
ax2.set_title('Love-2:\n$y1=0.6*\sqrt{|x|}+\sqrt{\\frac {1-x^2}{2}}$\n$y2=0.6*\sqrt{|x|}-\sqrt{\\frac {1-x^2}{2}}#39;)
x=np.linspace(-1,1,1000)
#y1 = 0.6 * abs(x)**0.5 + ((1 - x**2) / 2)**0.5
y1 = 0.6 * np.sqrt(abs(x)) + np.sqrt((1 - x**2) / 2)  # 等同于上面
y2 = 0.6 * abs(x)**0.5 - ((1 - x**2) / 2)**0.5
ax2.plot(x,y1,'r-')
ax2.plot(x,y2,'r-')

# 图三
ax3.set_title('Love-3:\n$x=2*(sin(t)-\\frac{sin(2t)}{2})$\n$y=2*(cos(t)-cos(t)^2)#39;)
t=np.linspace(-np.pi,np.pi,1000)
x=2*(np.sin(t)-np.sin(2*t)/2)
y=2*(np.cos(t)-np.cos(t)**2)
ax3.plot(x,y,'r-')

# 图四
ax4.set_title('Love-4:\n$x^2+(y- \sqrt[3]{x^2})^2=1#39;)
x = np.linspace(-1,1,1000)
y1 = np.sqrt(1 - x**2) + pow(np.abs(x),float(2)/float(3))
y2 = -np.sqrt(1 - x**2)+ pow(np.abs(x),float(2)/float(3))
ax4.plot(x, y1,'r-')
ax4.plot(x, y2,'r-')

# 图五
ax5.set_title('Love-5:\n$x = sin(t)$ , $y = cos(t) +\\sqrt[3]{x^2}#39;)
t = np.linspace(0, np.pi, 1000)
x = np.sin(t)
y = np.cos(t) + np.power(x, 2.0 / 3) 
ax5.plot(x, y, 'r-')
ax5.plot(-x, y, 'r-') 

# 图六
ax6.set_title('Love-6:\n$r = \\frac{sin(t)*|(cos(t))^{0.7}| }{sin(t) + \\frac{7}{5}}- 2*sin(t) + 2$\n$x = r*cos(t)$ , $y = r*sin(t)#39;)
t=np.linspace(-180,180,2000)
r = np.sin(t) * (abs(np.cos(t))**0.7) / (np.sin(t) + 7 / 5) - 2 * np.sin(t) + 2
x = r*np.cos(t)
y = r*np.sin(t)
ax6.plot(x,y,'r-')

# 图七
ax7.set_title('Love-7:\n$x = 16*sin(t)^3$\n$y = 13*cos(t) - 5*cos(2t) - 2*cos(3t) -cos(4t)#39;)
t=np.linspace(-180,180,1000)
x = 16 * np.sin(t)**3
y = 13 * np.cos(t) - 5 * np.cos(2 * t) - 2 * np.cos(3 * t) - np.cos(4 * t)
ax7.plot(x,y,'r-')

# 图八
ax8.set_title('Love-8:\n$17x^2-16|x|y+17y^2=225#39;)
x1=np.linspace(-np.sqrt(17),0,1000)
y1 = -x1*8/17+np.sqrt(np.abs(225/17-225*x1**2/289))
y2 = -x1*8/17-np.sqrt(np.abs(225/17-225*x1**2/289))

x2=np.linspace(0,np.sqrt(17),1000)
y3 = x2*8/17+np.sqrt(np.abs(225/17-225*x2**2/289))
y4 = x2*8/17-np.sqrt(np.abs(225/17-225*x2**2/289))

ax8.plot(x1,y1,'r-')
ax8.plot(x1,y2,'r-')

ax8.plot(x2,y3,'r-')
ax8.plot(x2,y4,'r-')

# 图九
ax9.set_title('Love-9:\n$x = sin(t)*cos(t)*log(|t|)$\n$y = |t|^{0.3}*\\sqrt{cos(t)}#39;)
t=np.linspace(-1,1,2000)
x = np.sin(t)*np.cos(t)*np.log(abs(t))
y = abs(t)**0.3*np.sqrt(np.cos(t))
ax9.plot(x,y,'r-')

ax1.axis('off')
ax2.axis('off')
ax3.axis('off')
ax4.axis('off')
ax5.axis('off')
ax6.axis('off')
ax7.axis('off')
ax8.axis('off')
ax9.axis('off')

plt.show()


四、图片:

五、说明:

11款爱心数学方程式,理工男的爱心大放送,本人原创,python的matplotlib可视化方程式。

免费分享出来,供大家学习使用。

控制面板
您好,欢迎到访网站!
  查看权限
网站分类
最新留言