This example is kindly contributed by FreddyBaudine for reproducing pygae/galgebra#26 and pygae/galgebra#30 with modifications by utensil.
Please note before Python code, there's an invisible markdown cell with the following code to enable color
and define some colors from http://latexcolor.com/:
$$
\require{color}
\definecolor{airforceblue}{rgb}{0.36, 0.54, 0.66}
\definecolor{applegreen}{rgb}{0.55, 0.71, 0.0}
\definecolor{atomictangerine}{rgb}{1.0, 0.6, 0.4}
$$
In [1]:
from __future__ import print_function
import sys
from galgebra.printer import Format, xpdf
Format()
from sympy import symbols, sin, pi, latex, Array, permutedims
from galgebra.ga import Ga
In [2]:
from IPython.display import Math
In [3]:
from sympy import cos, sin, symbols
g3coords = (x,y,z) = symbols('x y z')
g3 = Ga('ex ey ez', g = [1,1,1], coords = g3coords,norm=False) # Create g3
(e_x,e_y,e_z) = g3.mv()
In [4]:
Math(r'g =%s' % latex(g3.g))
Out[4]:
In [5]:
sp2coords = (theta, phi) = symbols(r'{\color{airforceblue}\theta} {\color{applegreen}\phi}', real = True)
sp2param = [sin(theta)*cos(phi), sin(theta)*sin(phi), cos(theta)]
sp2 = g3.sm(sp2param, sp2coords, norm = False) # submanifold
(etheta, ephi) = sp2.mv() # sp2 basis vectors
(rtheta, rphi) = sp2.mvr() # sp2 reciprocal basis vectors
sp2grad = sp2.grad
sph_map = [1, theta, phi] # Coordinate map for sphere of r = 1
In [6]:
Math(r'(\theta,\phi)\rightarrow (r,\theta,\phi) = %s' % latex(sph_map))
Out[6]:
In [7]:
Math(r'e_\theta \cdot e_\theta = %s' % (etheta|etheta))
Out[7]:
In [8]:
Math(r'e_\phi \cdot e_\phi = %s' % (ephi|ephi))
Out[8]:
In [9]:
Math('g = %s' % latex(sp2.g))
Out[9]:
In [10]:
Math(r'g^{-1} = %s' % latex(sp2.g_inv))
Out[10]:
Christoffel symbols of the first kind:
In [11]:
Cf1 = sp2.Christoffel_symbols(mode=1)
Cf1 = permutedims(Array(Cf1), (2, 0, 1))
In [12]:
Math(r'\Gamma_{1, \alpha, \beta} = %s \quad \Gamma_{2, \alpha, \beta} = %s ' % (latex(Cf1[0, :, :]), latex(Cf1[1, :, :])))
Out[12]:
In [13]:
Cf2 = sp2.Christoffel_symbols(mode=2)
Cf2 = permutedims(Array(Cf2), (2, 0, 1))
In [14]:
Math(r'\Gamma^{1}_{\phantom{1,}\alpha, \beta} = %s \quad \Gamma^{2}_{\phantom{2,}\alpha, \beta} = %s ' % (latex(Cf2[0, :, :]), latex(Cf2[1, :, :])))
Out[14]:
In [15]:
F = sp2.mv('F','vector',f=True) #scalar function
f = sp2.mv('f','scalar',f=True) #vector function
In [16]:
Math(r'\nabla = %s' % sp2grad)
Out[16]:
In [17]:
Math(r'\nabla f = %s' % (sp2.grad * f))
Out[17]:
In [18]:
Math(r'F = %s' % F)
Out[18]:
In [19]:
Math(r'\nabla F = %s' % (sp2.grad * F))
Out[19]:
In [20]:
cir_th = phi = symbols(r'{\color{atomictangerine}\phi}',real = True)
cir_map = [pi/8, phi]
In [21]:
Math(r'(\phi)\rightarrow (\theta,\phi) = %s' % latex(cir_map))
Out[21]:
In [22]:
cir1d = sp2.sm( cir_map , (cir_th,), norm = False) # submanifold
cir1dgrad = cir1d.grad
(ephi) = cir1d.mv()
In [23]:
Math(r'e_\phi \cdot e_\phi = %s' % latex(ephi[0] | ephi[0]))
Out[23]:
In [24]:
Math('g = %s' % latex(cir1d.g))
Out[24]:
In [25]:
h = cir1d.mv('h','scalar',f= True)
H = cir1d.mv('H','vector',f= True)
In [26]:
Math(r'\nabla = %s' % cir1dgrad)
Out[26]:
In [27]:
Math(r'\nabla h = %s' %(cir1d.grad * h).simplify())
Out[27]:
In [28]:
Math('H = %s' % H)
Out[28]:
In [29]:
Math(r'\nabla H = %s' % (cir1d.grad * H).simplify())
Out[29]:
In [ ]: