欧几里得平面上的矢量微积分¶
本教程将在2维欧几里得空间的框架中介绍SageMath的一些向量演算功能。相应的工具已经通过 SageManifolds 项目。
The tutorial is also available as a Jupyter notebook, either
passive (nbviewer
)
or interactive (binder
).
1.定义欧几里得平面¶
我们定义了欧几里得平面 mathbb{E}^2 作为具有笛卡尔坐标的二维欧几里德空间 (x,y) ,通过函数 EuclideanSpace
**
sage: E.<x,y> = EuclideanSpace()
sage: E
Euclidean plane E^2
由于使用了 <x,y>
在上面的命令中,Python变量 x
和 y
被赋值给符号变量 x 和 y 描述笛卡尔坐标(不需要通过 var()
,即打字 x, y = var('x y')
):
sage: type(y)
<class 'sage.symbolic.expression.Expression'>
不是使用变量 x
和 y
,还可以通过坐标在笛卡尔坐标图表中的索引来访问坐标:
sage: cartesian = E.cartesian_coordinates()
sage: cartesian
Chart (E^2, (x, y))
sage: cartesian[1]
x
sage: cartesian[2]
y
sage: y is cartesian[2]
True
每个笛卡尔坐标都跨越整个实线::
sage: cartesian.coord_range()
x: (-oo, +oo); y: (-oo, +oo)
2.矢量场¶
欧几里得平面 mathbb{E}^2 规范地赋予与笛卡尔坐标相关联的向量框架:
sage: E.default_frame()
Coordinate frame (E^2, (e_x,e_y))
矢量场打开 mathbb{E}^2 然后根据其在该框架中的组件定义:
sage: v = E.vector_field(-y, x, name='v')
sage: v.display()
v = -y e_x + x e_y
对各个组件的访问由方括号运算符执行::
sage: v[1]
-y
sage: v[:]
[-y, x]
矢量场的曲线图 v (这是默认参数,请参阅的文档 plot()
对于各种选项):
sage: v.plot()
Graphics object consisting of 80 graphics primitives
还可以通过设置第二阶段中的分量来定义矢量场:
sage: w = E.vector_field(name='w')
sage: w[1] = function('w_x')(x,y)
sage: w[2] = function('w_y')(x,y)
sage: w.display()
w = w_x(x, y) e_x + w_y(x, y) e_y
请注意,在上面的示例中, w 是未指定的函数 (x,y) ,与组件相反 v 。
标准线性代数运算可以在向量场上执行:
sage: s = 2*v + x*w
sage: s.display()
(x*w_x(x, y) - 2*y) e_x + (x*w_y(x, y) + 2*x) e_y
标量积与范数¶
点(或标量)积 ucdot v 向量场的 u 和 v 由操作员获得 dot_product()
;它在上产生一个标量域 mathbb{E}^2 **
sage: s = v.dot_product(w)
sage: s
Scalar field v.w on the Euclidean plane E^2
的快捷方式别名 dot_product()
是 dot
**
sage: s == v.dot(w)
True
sage: s.display()
v.w: E^2 → ℝ
(x, y) ↦ -y*w_x(x, y) + x*w_y(x, y)
表示标量字段的符号表达式 vcdot w 是通过该方法获得的 expr()
**
sage: s.expr()
-y*w_x(x, y) + x*w_y(x, y)
向量场的欧几里得范数 v 上的标量字段 mathbb{E}^2 **
sage: s = norm(v)
sage: s.display()
|v|: E^2 → ℝ
(x, y) ↦ sqrt(x^2 + y^2)
同样,相应的符号表达式是通过 expr()
**
sage: s.expr()
sqrt(x^2 + y^2)
sage: norm(w).expr()
sqrt(w_x(x, y)^2 + w_y(x, y)^2)
我们当然有 |v|^2 = vcdot v **
sage: norm(v)^2 == v.dot(v)
True
在给定点的值¶
我们引入了一个观点 pin mathbb{E}^2 通过通用的SageMath语法从其父元素(此处为 mathbb{E}^2 ),即呼叫运营商 ()
,将点的笛卡尔坐标作为第一个参数::
sage: p = E((-2,3), name='p')
sage: p
Point p on the Euclidean plane E^2
的坐标 p 由该方法返回 coord()
**
sage: p.coord()
(-2, 3)
或者通过让图表 cartesian
针对以下要点采取行动::
sage: cartesian(p)
(-2, 3)
标量字段的值 s = norm(v)
在… p 是::
sage: s(p)
sqrt(13)
向量场的值在 p 是通过该方法获得的 at()
(因为呼叫接线员 ()
是为标量字段上的操作保留的,请参见 作为派生的矢量场 下图):
sage: vp = v.at(p)
sage: vp
Vector v at Point p on the Euclidean plane E^2
sage: vp.display()
v = -3 e_x - 2 e_y
sage: wp = w.at(p)
sage: wp.display()
w = w_x(-2, 3) e_x + w_y(-2, 3) e_y
sage: s = v.at(p) + pi*w.at(p)
sage: s.display()
(pi*w_x(-2, 3) - 3) e_x + (pi*w_y(-2, 3) - 2) e_y
3.微分运算符¶
标准运算符 mathrm{grad} , mathrm{div} 等可作为标量场和矢量场上的方法访问(例如 v.div()
)。然而,要使用标准的数学记数法(例如 div(v)
),让我们导入函数 grad()
, div()
,以及 laplacian()
在全局命名空间::
sage: from sage.manifolds.operators import *
分歧¶
向量场的散度由函数返回 div()
;输出为上的标量字段 mathbb{E}^2 **
sage: div(v)
Scalar field div(v) on the Euclidean plane E^2
sage: div(v).display()
div(v): E^2 → ℝ
(x, y) ↦ 0
在目前的情况下, mathrm{div}, v 消失的方式相同::
sage: div(v) == 0
True
相反,两国之间的分歧 w 是::
sage: div(w).display()
div(w): E^2 → ℝ
(x, y) ↦ d(w_x)/dx + d(w_y)/dy
sage: div(w).expr()
diff(w_x(x, y), x) + diff(w_y(x, y), y)
梯度¶
标量场的梯度,例如 s = norm(v)
,由函数返回 grad()
;输出为向量场::
sage: s = norm(v)
sage: grad(s)
Vector field grad(|v|) on the Euclidean plane E^2
sage: grad(s).display()
grad(|v|) = x/sqrt(x^2 + y^2) e_x + y/sqrt(x^2 + y^2) e_y
sage: grad(s)[2]
y/sqrt(x^2 + y^2)
对于通用标量字段,如::
sage: F = E.scalar_field(function('f')(x,y), name='F')
我们有:
sage: grad(F).display()
grad(F) = d(f)/dx e_x + d(f)/dy e_y
sage: grad(F)[:]
[d(f)/dx, d(f)/dy]
当然,我们可以结合 grad()
和 div()
**
sage: grad(div(w)).display()
grad(div(w)) = (d^2(w_x)/dx^2 + d^2(w_y)/dxdy) e_x + (d^2(w_x)/dxdy + d^2(w_y)/dy^2) e_y
拉普拉斯算子¶
拉普拉斯运算符 Delta 是由函数 laplacian()
;它作用于标量字段::
sage: laplacian(F).display()
Delta(F): E^2 → ℝ
(x, y) ↦ d^2(f)/dx^2 + d^2(f)/dy^2
以及向量场:
sage: laplacian(w).display()
Delta(w) = (d^2(w_x)/dx^2 + d^2(w_x)/dy^2) e_x + (d^2(w_y)/dx^2 + d^2(w_y)/dy^2) e_y
对于标量域,我们有这样的恒等式
正如我们可以查看的:
sage: laplacian(F) == div(grad(F))
True
4.极坐标¶
极坐标 (r,phi) 在上介绍 mathbb{E}^2 发信人::
sage: polar.<r,ph> = E.polar_coordinates()
sage: polar
Chart (E^2, (r, ph))
sage: polar.coord_range()
r: (0, +oo); ph: [0, 2*pi] (periodic)
它们通过以下变换与笛卡尔坐标相关:
sage: E.coord_change(polar, cartesian).display()
x = r*cos(ph)
y = r*sin(ph)
sage: E.coord_change(cartesian, polar).display()
r = sqrt(x^2 + y^2)
ph = arctan2(y, x)
正交化向量架 (e_r, e_phi) 方法返回与极坐标相关联的 polar_frame()
**
sage: polar_frame = E.polar_frame()
sage: polar_frame
Vector frame (E^2, (e_r,e_ph))
sage: er = polar_frame[1]
sage: er.display()
e_r = x/sqrt(x^2 + y^2) e_x + y/sqrt(x^2 + y^2) e_y
上面的显示是在默认框架(笛卡尔框架)中使用默认坐标(笛卡尔)。让我们要求在同一帧中显示,但组件以极坐标表示:
sage: er.display(cartesian.frame(), polar)
e_r = cos(ph) e_x + sin(ph) e_y
同样::
sage: eph = polar_frame[2]
sage: eph.display()
e_ph = -y/sqrt(x^2 + y^2) e_x + x/sqrt(x^2 + y^2) e_y
sage: eph.display(cartesian.frame(), polar)
e_ph = -sin(ph) e_x + cos(ph) e_y
我们可以核对一下 (e_r, e_phi) 是一个正交化框架::
sage: all([er.dot(er) == 1, er.dot(eph) == 0, eph.dot(eph) == 1])
True
标量场可以用极坐标表示:
sage: F.display()
F: E^2 → ℝ
(x, y) ↦ f(x, y)
(r, ph) ↦ f(r*cos(ph), r*sin(ph))
sage: F.display(polar)
F: E^2 → ℝ
(r, ph) ↦ f(r*cos(ph), r*sin(ph))
我们可以用极坐标来求矢量场的分量:
sage: v.display() # default frame and default coordinates (both Cartesian ones)
v = -y e_x + x e_y
sage: v.display(polar_frame) # polar frame and default coordinates
v = sqrt(x^2 + y^2) e_ph
sage: v.display(polar_frame, polar) # polar frame and polar coordinates
v = r e_ph
sage: w.display()
w = w_x(x, y) e_x + w_y(x, y) e_y
sage: w.display(polar_frame, polar)
w = (cos(ph)*w_x(r*cos(ph), r*sin(ph)) + sin(ph)*w_y(r*cos(ph), r*sin(ph))) e_r
+ (-sin(ph)*w_x(r*cos(ph), r*sin(ph)) + cos(ph)*w_y(r*cos(ph), r*sin(ph))) e_ph
极坐标中的梯度¶
让我们用极坐标定义一个通用标量场:
sage: H = E.scalar_field({polar: function('h')(r,ph)}, name='H')
sage: H.display(polar)
H: E^2 → ℝ
(r, ph) ↦ h(r, ph)
的渐变 H 然后::
sage: grad(H).display(polar_frame, polar)
grad(H) = d(h)/dr e_r + d(h)/dph/r e_ph
对单个组件的访问是通过方括号运算符实现的,其中,除了索引之外,还必须指定向量帧和坐标(如果它们不是默认的坐标):
sage: grad(H).display(cartesian.frame(), polar)
grad(H) = (r*cos(ph)*d(h)/dr - sin(ph)*d(h)/dph)/r e_x + (r*sin(ph)*d(h)/dr
+ cos(ph)*d(h)/dph)/r e_y
sage: grad(H)[polar_frame, 2, polar]
d(h)/dph/r
极坐标中的散度¶
让我们用极坐标定义一个通用矢量场:
sage: u = E.vector_field(function('u_r')(r,ph),
....: function('u_ph', latex_name=r'u_\phi')(r,ph),
....: frame=polar_frame, chart=polar, name='u')
sage: u.display(polar_frame, polar)
u = u_r(r, ph) e_r + u_ph(r, ph) e_ph
它的分歧是::
sage: div(u).display(polar)
div(u): E^2 → ℝ
(r, ph) ↦ (r*d(u_r)/dr + u_r(r, ph) + d(u_ph)/dph)/r
sage: div(u).expr(polar)
(r*diff(u_r(r, ph), r) + u_r(r, ph) + diff(u_ph(r, ph), ph))/r
sage: div(u).expr(polar).expand()
u_r(r, ph)/r + diff(u_ph(r, ph), ph)/r + diff(u_r(r, ph), r)
默认情况下使用极坐标:¶
为了避免指定参数 polar_frame
和 polar
在……里面 display()
, expr()
和 []
,我们可以通过以下方式更改缺省值 set_default_chart()
和 set_default_frame()
**
sage: E.set_default_chart(polar)
sage: E.set_default_frame(polar_frame)
然后我们有::
sage: u.display()
u = u_r(r, ph) e_r + u_ph(r, ph) e_ph
sage: u[1]
u_r(r, ph)
sage: v.display()
v = r e_ph
sage: v[2]
r
sage: w.display()
w = (cos(ph)*w_x(r*cos(ph), r*sin(ph)) + sin(ph)*w_y(r*cos(ph), r*sin(ph))) e_r + (-sin(ph)*w_x(r*cos(ph), r*sin(ph)) + cos(ph)*w_y(r*cos(ph), r*sin(ph))) e_ph
sage: div(u).expr()
(r*diff(u_r(r, ph), r) + u_r(r, ph) + diff(u_ph(r, ph), ph))/r
5.高级主题:作为黎曼流形的欧几里得平面¶
mathbb{E}^2 实际上是一个 Riemannian manifold (见 pseudo_riemannian
),即具有正定度量张量的光滑实流形:
sage: E.category()
Join of
Category of smooth manifolds over Real Field with 53 bits of precision and
Category of connected manifolds over Real Field with 53 bits of precision and
Category of complete metric spaces
sage: E.base_field() is RR
True
实际上 RR
在这里用作真实字段的代理(这在将来应该被替换,请参阅 :issue:`24456` ),而53位的精度当然不起到符号计算的作用。
的用户图集 mathbb{E}^2 有两个图表:
sage: E.atlas()
[Chart (E^2, (x, y)), Chart (E^2, (r, ph))]
上定义了三个向量帧 mathbb{E}^2 **
sage: E.frames()
[Coordinate frame (E^2, (e_x,e_y)),
Coordinate frame (E^2, (∂/∂r,∂/∂ph)),
Vector frame (E^2, (e_r,e_ph))]
Indeed, there are two frames associated with polar coordinates: the coordinate frame (frac{partial}{partial r}, frac{partial}{partial phi}) and the orthonormal frame (e_r, e_phi).
黎曼度量¶
的默认度量张量 mathbb{E}^2 是::
sage: g = E.metric()
sage: g
Riemannian metric g on the Euclidean plane E^2
sage: g.display()
g = e^r⊗e^r + e^ph⊗e^ph
在上面的显示中, e^r
= e^r 和 e^ph
= e^phi 定义余架的1-形式对正交极架对偶吗 (e_r, e_phi) ,这是默认的矢量帧 mathbb{E}^2 **
sage: polar_frame.coframe()
Coframe (E^2, (e^r,e^ph))
当然,我们可能会要求显示与默认帧不同的帧:
sage: g.display(cartesian.frame())
g = dx⊗dx + dy⊗dy
sage: g.display(polar.frame())
g = dr⊗dr + r^2 dph⊗dph
sage: g[:]
[1 0]
[0 1]
sage: g[polar.frame(),:]
[ 1 0]
[ 0 r^2]
g 是一种 flat 度量:其(黎曼)曲率张量(请参见 riemann()
)为零::
sage: g.riemann()
Tensor field Riem(g) of type (1,3) on the Euclidean plane E^2
sage: g.riemann().display()
Riem(g) = 0
公制 g 正在定义上的点积 mathbb{E}^2 **
sage: v.dot(w) == g(v,w)
True
sage: norm(v) == sqrt(g(v,v))
True
作为派生的矢量场¶
向量场充当标量场上的派生:
sage: v(F)
Scalar field v(F) on the Euclidean plane E^2
sage: v(F).display()
v(F): E^2 → ℝ
(x, y) ↦ -y*d(f)/dx + x*d(f)/dy
(r, ph) ↦ -r*sin(ph)*d(f)/d(r*cos(ph)) + r*cos(ph)*d(f)/d(r*sin(ph))
sage: v(F) == v.dot(grad(F))
True
sage: dF = F.differential()
sage: dF
1-form dF on the Euclidean plane E^2
sage: v(F) == dF(v)
True
The set mathfrak{X}(mathbb{E}^2) of all vector fields on mathbb{E}^2 is a free module of rank 2 over the commutative algebra of smooth scalar fields on mathbb{E}^2, C^infty(mathbb{E}^2):
sage: XE = v.parent()
sage: XE
Free module X(E^2) of vector fields on the Euclidean plane E^2
sage: XE.category()
Category of finite dimensional modules over Algebra of differentiable
scalar fields on the Euclidean plane E^2
sage: XE.base_ring()
Algebra of differentiable scalar fields on the Euclidean plane E^2
sage: CE = F.parent()
sage: CE
Algebra of differentiable scalar fields on the Euclidean plane E^2
sage: CE is XE.base_ring()
True
sage: CE.category()
Join of Category of commutative algebras over Symbolic Ring and Category of homsets of topological spaces
sage: rank(XE)
2
自由模的基 mathfrak{X}(mathbb{E}^2) 上定义的矢量帧 mathbb{E}^2 **
sage: XE.bases()
[Coordinate frame (E^2, (e_x,e_y)),
Coordinate frame (E^2, (∂/∂r,∂/∂ph)),
Vector frame (E^2, (e_r,e_ph))]
切空间¶
在点$p$上求值的向量场是切线空间中的一个向量 T_pmathbb{E}^2 **
sage: vp = v.at(p)
sage: vp.display()
v = -3 e_x - 2 e_y
sage: Tp = vp.parent()
sage: Tp
Tangent space at Point p on the Euclidean plane E^2
sage: Tp.category()
Category of finite dimensional vector spaces over Symbolic Ring
sage: dim(Tp)
2
sage: isinstance(Tp, FiniteRankFreeModule)
True
sage: sorted(Tp.bases(), key=str)
[Basis (e_r,e_ph) on the Tangent space at Point p on the Euclidean plane E^2,
Basis (e_x,e_y) on the Tangent space at Point p on the Euclidean plane E^2]
Levi-Civita连接¶
与欧氏度规相关的Levi-Civita联络 g 是::
sage: nabla = g.connection()
sage: nabla
Levi-Civita connection nabla_g associated with the Riemannian metric g on the Euclidean plane E^2
相对于极坐标的相应Christoffel符号为:
sage: g.christoffel_symbols_display()
Gam^r_ph,ph = -r
Gam^ph_r,ph = 1/r
By default, only nonzero and nonredundant values are displayed (for instance Gamma^phi_{, phi r} is skipped, since it can be deduced from Gamma^phi_{, r phi} by symmetry on the last two indices).
相对于笛卡尔坐标的Christoffel符号均为零:
sage: g.christoffel_symbols_display(chart=cartesian, only_nonzero=False)
Gam^x_xx = 0
Gam^x_xy = 0
Gam^x_yy = 0
Gam^y_xx = 0
Gam^y_xy = 0
Gam^y_yy = 0
nabla_g 差分运算符中是否涉及连接:
sage: grad(F) == nabla(F).up(g)
True
sage: nabla(F) == grad(F).down(g)
True
sage: div(v) == nabla(v).trace()
True
sage: div(w) == nabla(w).trace()
True
sage: laplacian(F) == nabla(nabla(F).up(g)).trace()
True
sage: laplacian(w) == nabla(nabla(w).up(g)).trace(1,2)
True