sp2sp3.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 "# A geometric algebra for the unit sphere in R^3 \n", 46 "# as a submanifold of R^3 with spherical coordintes.\n", 47 "\n", 48 "# Make SymPy available to this program:\n", 49 "import sympy \n", 50 "from sympy import *\n", 51 "\n", 52 "# Make GAlgebra available to this program:\n", 53 "from galgebra.ga import * \n", 54 "from galgebra.mv import *\n", 55 "from galgebra.printer import Fmt, GaPrinter, Format\n", 56 " # Fmt: sets the way that a multivector's basis expansion is output.\n", 57 " # GaPrinter: makes GA output a little more readable.\n", 58 " # Format: turns on latex printer.\n", 59 "from galgebra.gprinter import gFormat, gprint\n", 60 "gFormat()" 61 ] 62 }, 63 { 64 "cell_type": "code", 65 "execution_count": 2, 66 "metadata": {}, 67 "outputs": [], 68 "source": [ 69 "# A geometric algebra for the unit sphere in R^3 \n", 70 "# as a submanifold of R^3 with spherical coordintes.\n", 71 "\n", 72 "# sp3: Base manifold\n", 73 "sp3coords = (r, phi, theta) = symbols('r phi theta', real=True) \n", 74 "sp3 = Ga('e', g=None, coords=sp3coords, \\\n", 75 " X=[r*sin(phi)*cos(theta), r*sin(phi)*sin(theta), r*cos(phi)], norm=True)\n", 76 "(er, ephi, etheta) = sp3.mv()\n", 77 "\n", 78 "# sp2: Submanifold\n", 79 "sp2coords = (p,t) = symbols('phi theta', real=True) # they output as Greek phi and theta\n", 80 " # Parameterize the unit sphere using the spherical coordinates of sp3:\n", 81 "sp2param = [1, p, t] \n", 82 " # Map the sp3 coordinates of the sphere to its sp2 coordinates:\n", 83 "sp2 = sp3.sm(sp2param, sp2coords, norm=True)\n", 84 "\n", 85 "(ep, et) = sp2.mv()\n", 86 "(rp, rt) = sp2.mvr()\n", 87 "\n", 88 "# Derivatives\n", 89 "grad = sp2.grad\n", 90 "from galgebra.dop import *\n", 91 "pdph = Pdop(p)\n", 92 "pdth = Pdop(t)" 93 ] 94 }, 95 { 96 "cell_type": "code", 97 "execution_count": 3, 98 "metadata": {}, 99 "outputs": [ 100 { 101 "data": { 102 "text/latex": [ 103 "$\\displaystyle \\boldsymbol{e}_{\\phi } \\frac{\\partial}{\\partial \\phi } + \\boldsymbol{e}_{\\theta } \\frac{1}{\\sin{\\left (\\phi \\right )}} \\frac{\\partial}{\\partial \\theta } $" 104 ], 105 "text/plain": [ 106 "<IPython.core.display.Math object>" 107 ] 108 }, 109 "metadata": {}, 110 "output_type": "display_data" 111 } 112 ], 113 "source": [ 114 "gprint(grad) " 115 ] 116 }, 117 { 118 "cell_type": "code", 119 "execution_count": null, 120 "metadata": {}, 121 "outputs": [], 122 "source": [] 123 } 124 ], 125 "metadata": { 126 "kernelspec": { 127 "display_name": "Python 3 (ipykernel)", 128 "language": "python", 129 "name": "python3" 130 }, 131 "language_info": { 132 "codemirror_mode": { 133 "name": "ipython", 134 "version": 3 135 }, 136 "file_extension": ".py", 137 "mimetype": "text/x-python", 138 "name": "python", 139 "nbconvert_exporter": "python", 140 "pygments_lexer": "ipython3", 141 "version": "3.11.8" 142 } 143 }, 144 "nbformat": 4, 145 "nbformat_minor": 4 146 }