亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

python+matplotlib演示電偶極子實例代碼

系統 2085 0

使用matplotlib.tri.CubicTriInterpolator.演示變化率計算:

python+matplotlib演示電偶極子實例代碼_第1張圖片

完整實例:

            
from matplotlib.tri import (
  Triangulation, UniformTriRefiner, CubicTriInterpolator)
import matplotlib.pyplot as plt
import matplotlib.cm as cm
import numpy as np


#-----------------------------------------------------------------------------
# Electrical potential of a dipole
#-----------------------------------------------------------------------------
def dipole_potential(x, y):
  """ The electric dipole potential V """
  r_sq = x**2 + y**2
  theta = np.arctan2(y, x)
  z = np.cos(theta)/r_sq
  return (np.max(z) - z) / (np.max(z) - np.min(z))


#-----------------------------------------------------------------------------
# Creating a Triangulation
#-----------------------------------------------------------------------------
# First create the x and y coordinates of the points.
n_angles = 30
n_radii = 10
min_radius = 0.2
radii = np.linspace(min_radius, 0.95, n_radii)

angles = np.linspace(0, 2 * np.pi, n_angles, endpoint=False)
angles = np.repeat(angles[..., np.newaxis], n_radii, axis=1)
angles[:, 1::2] += np.pi / n_angles

x = (radii*np.cos(angles)).flatten()
y = (radii*np.sin(angles)).flatten()
V = dipole_potential(x, y)

# Create the Triangulation; no triangles specified so Delaunay triangulation
# created.
triang = Triangulation(x, y)

# Mask off unwanted triangles.
triang.set_mask(np.hypot(x[triang.triangles].mean(axis=1),
             y[triang.triangles].mean(axis=1))
        < min_radius)

#-----------------------------------------------------------------------------
# Refine data - interpolates the electrical potential V
#-----------------------------------------------------------------------------
refiner = UniformTriRefiner(triang)
tri_refi, z_test_refi = refiner.refine_field(V, subdiv=3)

#-----------------------------------------------------------------------------
# Computes the electrical field (Ex, Ey) as gradient of electrical potential
#-----------------------------------------------------------------------------
tci = CubicTriInterpolator(triang, -V)
# Gradient requested here at the mesh nodes but could be anywhere else:
(Ex, Ey) = tci.gradient(triang.x, triang.y)
E_norm = np.sqrt(Ex**2 + Ey**2)

#-----------------------------------------------------------------------------
# Plot the triangulation, the potential iso-contours and the vector field
#-----------------------------------------------------------------------------
fig, ax = plt.subplots()
ax.set_aspect('equal')
# Enforce the margins, and enlarge them to give room for the vectors.
ax.use_sticky_edges = False
ax.margins(0.07)

ax.triplot(triang, color='0.8')

levels = np.arange(0., 1., 0.01)
cmap = cm.get_cmap(name='hot', lut=None)
ax.tricontour(tri_refi, z_test_refi, levels=levels, cmap=cmap,
       linewidths=[2.0, 1.0, 1.0, 1.0])
# Plots direction of the electrical vector field
ax.quiver(triang.x, triang.y, Ex/E_norm, Ey/E_norm,
     units='xy', scale=10., zorder=3, color='blue',
     width=0.007, headwidth=3., headlength=4.)

ax.set_title('Gradient plot: an electrical dipole')
plt.show()
          

總結

以上就是本文關于python+matplotlib演示電偶極子實例代碼的全部內容,希望對大家有所幫助。感興趣的朋友可以繼續參閱本站其他相關專題,如有不足之處,歡迎留言指出。感謝朋友們對本站的支持!


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦?。?!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 亚洲免费在线视频 | 天天爱夜夜操 | 免费 黄 色 人成 视频 | 午夜看一级特黄a大片 | 四虎音影| 国产精品图片 | 手机看片福利永久国产日韩 | 欧美亚洲日本国产综合网 | 国产成人一级片 | 免费视频精品一区二区三区 | 欧美洲精品亚洲精品中文字幕 | 久草免费在线观看 | 国外成人在线视频 | 日韩在线视频一区二区三区 | 男人在线网站 | 婷婷色香五月激情综合2020 | 四虎永久免费在线观看 | 一级片亚洲 | 亚洲精品αv一区二区三区 亚洲精品爱爱久久 | 日本视频不卡 | 四虎1515| 欧美日韩不卡中文字幕在线 | er久99久热只有精品国产 | 欧美激情欧美狂野欧美精品免费 | 久久精品欧美一区二区 | 99精品视频99| 欧美日韩成人高清色视频 | 成人性色生活影片 | 精品欧美高清一区二区免费 | 亚洲色欧美 | 欧美一区二区三 | 国产精品夜色视频一区二区 | 公主恋人ova | 久久婷五月综合 | 草久久久| 欧美高清理论片在线观看 | 欧美日韩国产在线人成 | 欧美日韩国产成人综合在线 | 国产黄色影院 | 麻豆精品视频 在线视频 | 国产三及 |