2.10

2023310143015發表於2024-10-28

點選檢視程式碼
import numpy as np
import pandas as pd
import sympy as sp
sp.init_printing(use_unicode=True)
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif']=['Times New Roman + SimSun + WFM Sans SC']
plt.rcParams['mathtext.fontset']='cm'
# Times New Roman + SimSun + WFM Sans SC
# simsum宋體, times new roman -*, simhei黑體, kaiti楷體,
# dengxian等線, fangsong仿宋, Microsoft Yahei微軟雅黑
plt.rcParams['axes.unicode_minus']=False
plt.rcParams['figure.dpi'] = 200
# plt.rcParams['figure.figsize'] = [4, 3]
# plt.rcParams['font.size'] = 12
plt.rcParams['xtick.direction'] = 'in'
plt.rcParams['ytick.direction'] = 'in'
u1 = np.linspace(0, np.pi*(2/3), 1000)
u2 = np.linspace(np.pi*(1/3), np.pi, 1000)
v = np.linspace(-np.pi, np.pi, 1000)
u1, V = np.meshgrid(u1, v)
u2, V = np.meshgrid(u2, v)
x1 = 2*np.sin(u1)*np.cos(V)
y1 = 2*np.sin(u1)*np.sin(V)
x2 = 2*np.sin(u2)*np.cos(V)
y2 = 2*np.sin(u2)*np.sin(V)
z1 = 2 + 2*np.cos(u1)
z2 = 2*np.cos(u2)
fig = plt.figure(dpi=500)
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(x1, y1, z1, cmap='Blues_r')
ax.plot_surface(x2, y2, z2, cmap='Blues')
ax.set_box_aspect((1, 1, 1))  # x、y、z軸刻度之比為1:1:1
ax.set_xlim(-3, 2)
ax.set_ylim(-2, 3)
ax.set_zlim(-2, 3)
y = sp.var('y')
f1 = sp.pi*(4*y - y**2)
f2 = sp.pi*(4 - y**2)
V = sp.integrate(f1, (y, 1, 3)) + sp.integrate(f2, (y, -2, 1))
W = 1000*sp.Rational(98, 10)*\
    (sp.integrate(f1*(3-y), (y, 1, 3)) + sp.integrate(f2*(3-y), (y, -2, 1)))
V, W
print((V, W))

相關文章