# 磁場與安培定律
東華大學_普通物理_葉旺奇作業
###### tags: `physis`
###### 普通物理AF-410621205-郭新拳-磁場與安培定律
----
### Work1-長直導線的磁場
###### 其中 B 是磁場,向量 r 是從路徑元素到場的位置向量,r 的長度為此向量的大小,μ0 是真空磁導率,i 是電流,ds 是電流的微小路徑元素。
##### 必歐-沙伐公式:
<span class="MathJax" id="MathJax-Element-1-Frame" tabindex="0" data-mathml="<math xmlns="http://www.w3.org/1998/Math/MathML"><mrow class="MJX-TeXAtom-ORD"><mi mathvariant="normal">d</mi></mrow><mrow class="MJX-TeXAtom-ORD"><mover><mi>B</mi><mo stretchy="false">&#x2192;</mo></mover></mrow><mo>=</mo><mstyle displaystyle="true" scriptlevel="0"><mfrac><msub><mi>&#x03BC;</mi><mn>0</mn></msub><mrow><mn>4</mn><mi>&#x03C0;</mi></mrow></mfrac><mfrac><mrow><mi>i</mi><mrow class="MJX-TeXAtom-ORD"><mi mathvariant="normal">d</mi></mrow><mrow class="MJX-TeXAtom-ORD"><mover><mi>s</mi><mo stretchy="false">&#x2192;</mo></mover></mrow><mo>&#x00D7;</mo><mrow class="MJX-TeXAtom-ORD"><mover><mi>r</mi><mo stretchy="false">&#x2192;</mo></mover></mrow></mrow><msup><mi>r</mi><mn>3</mn></msup></mfrac></mstyle></math>" role="presentation" style="position: relative;"><span class="math" id="MathJax-Span-1" style="width: 9.402em; display: inline-block;"><span style="display: inline-block; position: relative; width: 7.503em; height: 0px; font-size: 125%;"><span style="position: absolute; clip: rect(0.753em, 1007.5em, 3.252em, -999.998em); top: -2.348em; left: 0em;"><span class="mrow" id="MathJax-Span-2"><span class="texatom" id="MathJax-Span-3"><span class="mrow" id="MathJax-Span-4"><span class="mi" id="MathJax-Span-5" style="font-family: MathJax_Main;">d</span></span></span><span class="texatom" id="MathJax-Span-6"><span class="mrow" id="MathJax-Span-7"><span class="munderover" id="MathJax-Span-8"><span style="display: inline-block; position: relative; width: 0.753em; height: 0px;"><span style="position: absolute; clip: rect(3.152em, 1000.75em, 4.152em, -999.998em); top: -3.998em; left: 0em;"><span class="mi" id="MathJax-Span-9" style="font-family: MathJax_Math-italic;">B</span><span style="display: inline-block; width: 0px; height: 4.002em;"></span></span><span style="position: absolute; top: -4.298em; left: 0.253em;"><span style="height: 0em; vertical-align: 0em; width: 0.453em; display: inline-block; overflow: hidden;"></span><span class="mo" id="MathJax-Span-10" style="font-family: MathJax_Main;">⃗ <span style="height: 0em; vertical-align: 0em; margin-left: -0.247em;"></span></span><span style="display: inline-block; overflow: hidden; height: 1px; width: 0em;"></span><span style="display: inline-block; width: 0pxheight: 4.002em;"></span></span></span></span></span></span><span class="mo" id="MathJax-Span-11" style="font-family: MathJax_Main; padding-left: 0.302em;">=</span><span class="mstyle" id="MathJax-Span-12" style="padding-left: 0.302em;"><span class="mrow" id="MathJax-Span-13"><span class="mfrac" id="MathJax-Span-14"><span style="display: inline-block; position: relative; width: 1.203em; height: 0px; margin-right: 0.102em; margin-left: 0.102em;"><span style="position: absolute; clip: rect(3.402em, 1001.05em, 4.353em, -999.998em); top: -4.697em; left: 50%; margin-left: -0.497em;"><span class="msubsup" id="MathJax-Span-15"><span style="display: inline-block; position: relative; width: 1.052em; height: 0px;"><span style="position: absolute; clip: rect(3.402em, 1000.6em, 4.353em, -999.998em); top: -3.998em; left: 0em;"><span class="mi" id="MathJax-Span-16" style="font-family: MathJax_Math-italic;">μ</span><span style="display: inline-block; width: 0px; height: 4.002em;"></span></span><span style="position: absolute; top: -3.848em; left: 0.603em;"><span class="mn" id="MathJax-Span-17" style="font-size: 70.7%; font-family: MathJax_Main;">0</span><span style="display: inline-block; width: 0px; height: 4.002em;"></span></span></span></span><span style="display: inline-block; width: 0px; height: 4.002em;"></span></span><span style="position: absolute; clip: rect(3.152em, 1001.05em, 4.152em, -999.998em); top: -3.298em; left: 50%; margin-left: -0.547em;"><span class="mrow" id="MathJax-Span-18"><span class="mn" id="MathJax-Span-19" style="font-family: MathJax_Main;">4</span><span class="mi" id="MathJax-Span-20" style="font-family: MathJax_Math-italic;">π<span style="display: inline-block; overflow: hidden; height: 1px; width: 0.003em;"></span></span></span><span style="display: inline-block; width: 0px; height: 4.002em;"></span></span><span style="position: absolute; clip: rect(0.853em, 1001.2em, 1.203em, -999.998em); top: -1.248em; left: 0em;"><span style="display: inline-block; overflow: hidden; vertical-align: 0em; border-top: 1.3px solid; width: 1.203em; height: 0px;"></span><span style="display: inline-block; width: 0px; height: 1.052em;"></span></span></span></span><span class="mfrac" id="MathJax-Span-21"><span style="display: inline-block; position: relative; width: 3.202em; height: 0px; margin-right: 0.102em; margin-left: 0.102em;"><span style="position: absolute; clip: rect(3.103em, 1003em, 4.152em, -999.998em); top: -4.697em; left: 50%; margin-left: -1.547em;"><span class="mrow" id="MathJax-Span-22"><span class="mi" id="MathJax-Span-23" style="font-family: MathJax_Math-italic;">i</span><span class="texatom" id="MathJax-Span-24"><span class="mrow" id="MathJax-Span-25"><span class="mi" id="MathJax-Span-26" style="font-family: MathJax_Main;">d</span></span></span><span class="texatom" id="MathJax-Span-27"><span class="mrow" id="MathJax-Span-28"><span class="munderover" id="MathJax-Span-29"><span style="display: inline-block; position: relative; width: 0.503em; height: 0px;"><span style="position: absolute; clip: rect(3.402em, 1000.4em, 4.152em, -999.998em); top: -3.998em; left: 0em;"><span class="mi" id="MathJax-Span-30" style="font-family: MathJax_Math-italic;">s</span><span style="display: inline-block; width: 0px; height: 4.002em;"></span></span><span style="position: absolute; top: -4.048em; left: 0.053em;"><span style="height: 0em; vertical-align: 0em; width: 0.453em; display: inline-block; overflow: hidden;"></span><span class="mo" id="MathJax-Span-31" style="font-family: MathJax_Main;">⃗ <span style="height: 0em; vertical-align: 0em; margin-left: -0.247em;"></span></span><span style="display: inline-block; overflow: hidden; height: 1px; width: 0em;"></span><span style="display: inline-block; width: 0px; height: 4.002em;"></span></span></span></span></span></span><span class="mo" id="MathJax-Span-32" style="font-family: MathJax_Main; padding-left: 0.202em;">×</span><span class="texatom" id="MathJax-Span-33" style="padding-left: 0.202em;"><span class="mrow" id="MathJax-Span-34"><span class="munderover" id="MathJax-Span-35"><span style="display: inline-block; position: relative; width: 0.503em; height: 0px;"><span style="position: absolute; clip: rect(3.402em, 1000.45em, 4.152em, -999.998em); top: -3.998em; left: 0em;"><span class="mi" id="MathJax-Span-36" style="font-family: MathJax_Math-italic;">r</span><span style="display: inline-block; width: 0px; height: 4.002em;"></span></span><span style="position: absolute; top: -4.048em; left: 0.053em;"><span style="height: 0em; vertical-align: 0em; width: 0.453em; display: inline-block; overflow: hidden;"></span><span class="mo" id="MathJax-Span-37" style="font-family: MathJax_Main;">⃗ <span style="height: 0em; vertical-align: 0em; margin-left: -0.247em;"></span></span><span style="display: inline-block; overflow: hidden; height: 1px; width: 0em;"></span><span style="display: inline-block; width: 0px; height: 4.002em;"></span></span></span></span></span></span></span><span style="display: inline-block; width: 0px; height: 4.002em;"></span></span><span style="position: absolute; clip: rect(3.103em, 1000.9em, 4.152em, -999.998em); top: -3.298em; left: 50%; margin-left: -0.447em;"><span class="msubsup" id="MathJax-Span-38"><span style="display: inline-block; position: relative; width: 0.903em; height: 0px;"><span style="position: absolute; clip: rect(3.402em, 1000.45em, 4.152em, -999.998em); top: -3.998em; left: 0em;"><span class="mi" id="MathJax-Span-39" style="font-family: MathJax_Math-italic;">r</span><span style="display: inline-block; width: 0px; height: 4.002em;"></span></span><span style="position: absolute; top: -4.298em; left: 0.453em;"><span class="mn" id="MathJax-Span-40" style="font-size: 70.7%; font-family: MathJax_Main;">3</span><span style="display: inline-block; width: 0px; height: 4.002em;"></span></span></span></span><span style="display: inline-block; width: 0px; height: 4.002em;"></span></span><span style="position: absolute; clip: rect(0.853em, 1003.2em, 1.203em, -999.998em); top: -1.248em; left: 0em;"><span style="display: inline-block; overflow: hidden; vertical-align: 0em; border-top: 1.3px solid; width: 3.202em; height: 0px;"></span><span style="display: inline-block; width: 0px; height: 1.052em;"></span></span></span></span></span></span></span><span style="display: inline-block; width: 0px; height: 2.353em;"></span></span></span><span style="display: inline-block; overflow: hidden; vertical-align: -0.997em; border-left: 0px solid; width: 0px; height: 2.878em;">
###### [參考資料](http://highscope.ch.ntu.edu.tw/wordpress/?p=48077)
###### 如果已知電流密度 $\smash{J}$ 可將公式改成
${\mathbf {dB}}={\frac {\mu _{0}}{4\pi }}{\dfrac {\stackrel\longrightarrow{\smash{J}\vphantom{i}\,}\times\stackrel\longrightarrow{\smash{r}\vphantom{i}\,}}
{|{\smash{r}}|^{2}}}\ {\mathrm {dv}}$
##### 向量 $\stackrel\longrightarrow{\smash{J}\vphantom{i}\,}$ 的長度代表電流強度,方向代表電流方向
#### 其中dv 代表著 將長直導線分割成許多微小長方形的體積
#### 畫出B-R關係圖,磁場隨著測量點遠離線圈的變化
![](https://i.imgur.com/9Z3Ou4l.jpg)
- 瓶頸:
如果測試點在長直導線內,則會有誤差,如何解釋
:::info
我認為是經由高斯定律推廣而得
:::
--->需要做規避
- 解決方法
## 向量修正法
```sql=
rho.x=coil.x
rho.y=coil.y
rho.z=0
```
得到rho方向的向量,其中coil.x 和 coil.y 為分割成許多微小長方體的x,y座標
```sql=
rho=rho.norm()
X=dP*rho
Y=(Jdirection.cross(rho)).norm()
Y*=r*dtheta
Z=dL*Jdirection
```
定出微小長方體,三個方向的向量
dp $\rightarrow$ 每次測量點距離z軸所增加的長度
dL$\rightarrow$ 每次測量點往z軸上升所增加的長度
dtheta$\rightarrow$ 每次測量點所增加的角度
Jdirection $\rightarrow$ 電流方向
```sql=
if p<line.radius:
if abs(dot(R,X))/X.mag<X.mag and dot(R,X)>0:
if abs(dot(R,Y))/Y.mag<Y.mag and dot(R,Y)>0:
if abs(dot(R,Z))/Z.mag< Z.mag and dot(R,Z)>0:
continue
```
![](https://i.imgur.com/9Z3Ou4l.jpg)
- 比較正射影長是否有超過 微小長方體邊長且內積結果須微零
## 對角線修正法
如果R向量長度小於diagonal則省略不計算此直
缺點無法判別是否處於微小長方體內部或外部
```sql=
diagonal=sqrt(dP*dP+dL*dL+(dtheta*r)*(dtheta*r))
```
![](https://i.imgur.com/d3398cF.jpg)
![](https://)
## 驗證結果
1.測試點距離和所受磁場強度成正比
$\mathbb{e.g.}$ 距離變為 $\mathbb{2}$倍,則磁場強度變為$\dfrac{1}{2}$
2.磁場方向為切線方向
----
### Work2-安培定律
$\oint _{{\mathbb {C}}}{\mathbf {B}}\cdot d{\boldsymbol {\ell }}=\mu _{0}I_{{enc}}$
###### ${\displaystyle \mathbb {C} } 是環繞著導線的閉合迴路, \mathbf {B} 是磁場, d\boldsymbol{\ell}是微小線元素向量,\\ \mu _{0}是磁常數, I_{{enc}}是閉合迴路 {\displaystyle \mathbb {C} } 所圍住的電流。$
##### [參考資料](https://zh.wikipedia.org/zh-tw/安培定律)
----
## 作圖
###### X軸代表距離線圈多少公尺,Y軸代表封閉路徑內索圍住的線圈電流乘上 $\mu _{0}$磁常數
![](https://i.imgur.com/VD6dShQ.jpg)
----
### code:
## 作業1:
```sql=
from visual import*
from visual.graph import*
#from math import*
scene=display(width=1000,height=800,background=color.white,center=(0,1,0))#畫視窗&背景
dots=sphere(color=color.red,radius=0.01,pos=(0,0,3))
line=cylinder(color=color.blue,radius=0.1,pos=(0,0,0),axis=(0,0,6),Length=6)
coil=vector(0,0,0)
f=gdots(color=color.red)
f1=gdots(color=color.green)
#J=I/A current density
Jdirection=vector(0,0,1)
J=Jdirection*1/(pi*line.radius*line.radius)
mui=4*pi*10**-7
R=vector(0,0,0)
dL=line.length/100
dP=line.radius/20
dtheta=2*pi/20
B=vector(0,0,0)
X=vector(0,0,0)
Y=vector(0,0,0)
Z=vector(0,0,0)
row=vector(0,0,0)
i=0
for p in arange(0.0,4*line.radius,2*line.radius/50):
i=i+1
dots.pos.x=p*cos(pi/4)
dots.pos.y=p*sin(pi/4)
B.x=0
B.y=0
B.z=0
#直角坐標轉圓柱座標
B1=vector(0,0,0)
check=0
for r in arange(0.01,line.radius,dP):
for theta in arange(0,2*pi,dtheta):
for L in arange(0.0,line.Length,dL):
coil.x=r*cos(theta)
coil.y=r*sin(theta)
coil.z=L
R=dots.pos-coil
diagonal=sqrt(dP*dP+dL*dL+(dtheta*r)*(dtheta*r))
row.x=coil.x
row.y=coil.y
row.z=0
row=row.norm()
X=dP*row
Y=(Jdirection.cross(row)).norm()
Y*=r*dtheta
Z=dL*Jdirection
if p<line.radius:
if abs(dot(R,X))/X.mag<X.mag and dot(R,X)>0:
if abs(dot(R,Y))/Y.mag<Y.mag and dot(R,Y)>0:
if abs(dot(R,Z))/Z.mag< Z.mag and dot(R,Z)>0:
continue
B+=cross(J,(R.norm()))*dP*dtheta*dL*r/R.mag2
#B+=cross( R, dL*line.pos.norm() )/R.mag2
#Rx dline /R^2
B*=mui/(4*pi)
f.plot(pos=(p,B.mag))
#for phi in arange(0,2*pi,dtheta):
#a=arrow(pos=sun.pos,color=color.black,axis=B)
#scene,center forward
```
## 作業2:
```sql=
from visual import*
from visual.graph import*
from math import*
scene=display(width=1000,height=800,background=color.white,center=(0,1,0))#畫視窗&背景
dots=sphere(color=color.red,radius=0.01,pos=(0,0,3))
line=cylinder(color=color.blue,radius=0.1,pos=(0,0,0),axis=(0,0,6),Length=6)
coil=vector(0,0,0)
f=gdots(color=color.red)
f1=gdots(color=color.green)
#J=I/A current density
Jdirection=vector(0,0,1)
J=Jdirection*1/(pi*line.radius*line.radius)
mui=4*pi*10**-7
R=vector(0,0,0)
dL=0.05
dP=line.radius/20
dtheta=2*pi/20
B=vector(0,0,0)
X=vector(0,0,0)
Y=vector(0,0,0)
Z=vector(0,0,0)
row=vector(0,0,0)
i=0
for p in arange(0.0,2*line.radius,2*line.radius/50):
s=0
for phi in arange(0,2*pi,dtheta):
dots.pos.x=p*cos(phi)
dots.pos.y=p*sin(phi)
B.x=0
B.y=0
B.z=0
#直角坐標轉圓柱座標
for r in arange(0.001,line.radius,dP):
for theta in arange(0,2*pi,dtheta):
for L in arange(0.0,line.Length,dL):
coil.x=r*cos(theta)
coil.y=r*sin(theta)
coil.z=L
R=dots.pos-coil
diagonal=sqrt(dP*dP+dL*dL+(dtheta*r)*(dtheta*r))
row.x=coil.x
row.y=coil.y
row.z=0
row=row.norm()
X=dP*row
Y=(Jdirection.cross(row)).norm()
Y*=r*dtheta
Z=dL*Jdirection
if p<line.radius:
if abs(dot(R,X))/X.mag<X.mag and dot(R,X)>0:
if abs(dot(R,Y))/Y.mag<Y.mag and dot(R,Y)>0:
if abs(dot(R,Z))/Z.mag< Z.mag and dot(R,Z)>0:
continue
B+=cross(J,(R.norm()))*dP*dtheta*dL*r/R.mag2
#B+=cross( R, dL*line.pos.norm() )/R.mag2
#Rx dline /R^2
B*=mui/(4*pi)
s+=dot(B,p*10/pi*B.norm() )
f.plot(pos=(p,s))
rate(1000)
#for phi in arange(0,2*pi,dtheta):
#a=arrow(pos=sun.pos,color=color.black,axis=B)
#scene,center forward
```