/ examples / primer / sp2g3.ipynb
sp2g3.ipynb
  1  {
  2   "cells": [
  3    {
  4     "cell_type": "code",
  5     "execution_count": 1,
  6     "metadata": {},
  7     "outputs": [
  8      {
  9       "data": {
 10        "text/latex": [
 11         "$\\displaystyle \\DeclareMathOperator{\\Tr}{Tr}$$\n",
 12         "$$\\DeclareMathOperator{\\Adj}{Adj}$$\n",
 13         "$$\\newcommand{\\bfrac}[2]{\\displaystyle\\frac{#1}{#2}}$$\n",
 14         "$$\\newcommand{\\lp}{\\left (}$$\n",
 15         "$$\\newcommand{\\rp}{\\right )}$$\n",
 16         "$$\\newcommand{\\paren}[1]{\\lp {#1} \\rp}$$\n",
 17         "$$\\newcommand{\\half}{\\frac{1}{2}}$$\n",
 18         "$$\\newcommand{\\llt}{\\left <}$$\n",
 19         "$$\\newcommand{\\rgt}{\\right >}$$\n",
 20         "$$\\newcommand{\\abs}[1]{\\left |{#1}\\right | }$$\n",
 21         "$$\\newcommand{\\pdiff}[2]{\\bfrac{\\partial {#1}}{\\partial {#2}}}$$\n",
 22         "$$\\newcommand{\\npdiff}[3]{\\bfrac{\\partial^{#3} {#1}}{\\partial {#2}^{#3}}}$$\n",
 23         "$$\\newcommand{\\lbrc}{\\left \\{}$$\n",
 24         "$$\\newcommand{\\rbrc}{\\right \\}}$$\n",
 25         "$$\\newcommand{\\W}{\\wedge}$$\n",
 26         "$$\\newcommand{\\prm}[1]{{#1}^{\\prime}}$$\n",
 27         "$$\\newcommand{\\ddt}[1]{\\bfrac{d{#1}}{dt}}$$\n",
 28         "$$\\newcommand{\\R}{\\dagger}$$\n",
 29         "$$\\newcommand{\\deriv}[3]{\\bfrac{d^{#3}#1}{d{#2}^{#3}}}$$\n",
 30         "$$\\newcommand{\\grade}[2]{\\left < {#1} \\right >_{#2}}$$\n",
 31         "$$\\newcommand{\\f}[2]{{#1}\\lp {#2} \\rp}$$\n",
 32         "$$\\newcommand{\\eval}[2]{\\left . {#1} \\right |_{#2}}$$\n",
 33         "$$\\newcommand{\\bs}[1]{\\boldsymbol{#1}}$$\n",
 34         "$$\\newcommand{\\grad}{\\bs{\\nabla}}$"
 35        ],
 36        "text/plain": [
 37         "<IPython.core.display.Math object>"
 38        ]
 39       },
 40       "metadata": {},
 41       "output_type": "display_data"
 42      }
 43     ],
 44     "source": [
 45      "# Unit sphere R^3 as a submanifold of g3 in cartesian coordinates\n",
 46      "\n",
 47      "# Make SymPy available to this program:\n",
 48      "import sympy \n",
 49      "from sympy import *\n",
 50      "\n",
 51      "# Make GAlgebra available to this program:\n",
 52      "from galgebra.ga import *  \n",
 53      "from galgebra.mv import *\n",
 54      "from galgebra.printer import Fmt, GaPrinter, Format\n",
 55      "    # Fmt:       sets the way that a multivector's basis expansion is output.\n",
 56      "    # GaPrinter: makes GA output a little more readable.\n",
 57      "    # Format:    turns on latex printer.\n",
 58      "from galgebra.gprinter import gFormat, gprint\n",
 59      "gFormat()"
 60     ]
 61    },
 62    {
 63     "cell_type": "code",
 64     "execution_count": 2,
 65     "metadata": {},
 66     "outputs": [],
 67     "source": [
 68      "# Unit sphere R^3 as a submanifold of g3 in cartesian coordinates\n",
 69      "\n",
 70      "# g3: Base manifold.\n",
 71      "g3coords = (x,y,z) = symbols('x y z', real=True) \n",
 72      "g3 = Ga(r'\\mathbf{e}', g=[1,1,1], coords=g3coords)\n",
 73      "(ex, ey, ez) = g3.mv()\n",
 74      "\n",
 75      "# sp2: Submanifold\n",
 76      "sp2coords = (phi,th) = symbols('phi theta', real=True)\n",
 77      "  # Parameterize unit sphere using the coordinates of g3:\n",
 78      "sp2param = [sin(phi)*cos(th), sin(phi)*sin(th), cos(phi)] \n",
 79      "  # Map the g3 coordinates of the sphere to its sp2 coordinates:\n",
 80      "sp2 = g3.sm(sp2param, sp2coords, norm=True)  # \"sm\" is submanifold\n",
 81      "\n",
 82      "(ephi, eth) = sp2.mv()\n",
 83      "(rphi, rth) = sp2.mvr()\n",
 84      "\n",
 85      "# Derivatives\n",
 86      "grad  = sp2.grad\n",
 87      "from galgebra.dop import *\n",
 88      "pdphi = Pdop(phi)\n",
 89      "pdth  = Pdop(th)"
 90     ]
 91    },
 92    {
 93     "cell_type": "code",
 94     "execution_count": 3,
 95     "metadata": {},
 96     "outputs": [
 97      {
 98       "data": {
 99        "text/latex": [
100         "$\\displaystyle \\mathbf{e}_{\\phi} \\frac{\\partial}{\\partial \\phi} + \\mathbf{e}_{\\theta} \\frac{1}{\\sin{\\left(\\phi \\right)}} \\frac{\\partial}{\\partial \\theta}$"
101        ],
102        "text/plain": [
103         "e_phi*D{phi} + e_theta*1/sin(phi)*D{theta}"
104        ]
105       },
106       "execution_count": 3,
107       "metadata": {},
108       "output_type": "execute_result"
109      }
110     ],
111     "source": [
112      "grad = sp2.grad\n",
113      "grad"
114     ]
115    },
116    {
117     "cell_type": "code",
118     "execution_count": null,
119     "metadata": {},
120     "outputs": [],
121     "source": []
122    }
123   ],
124   "metadata": {
125    "kernelspec": {
126     "display_name": "Python 3 (ipykernel)",
127     "language": "python",
128     "name": "python3"
129    },
130    "language_info": {
131     "codemirror_mode": {
132      "name": "ipython",
133      "version": 3
134     },
135     "file_extension": ".py",
136     "mimetype": "text/x-python",
137     "name": "python",
138     "nbconvert_exporter": "python",
139     "pygments_lexer": "ipython3",
140     "version": "3.11.8"
141    }
142   },
143   "nbformat": 4,
144   "nbformat_minor": 4
145  }