Sunday 28 July 2019

Question about geodesic on sphere

I am working from Sean Carroll's Spacetime and Geometry : An Introduction to General Relativity and have got to the geodesic equation. I wanted to test it on the surface of a sphere where I know that great circles are geodesics and is about the simplest non-trivial case I can think of.

Carroll derives the geodesic equation:
\begin{align}
\frac{d^2x^\sigma}{d\lambda^2}+\Gamma_{\mu\nu}^\sigma\frac{dx^\mu}{d\lambda}\frac{dx^\nu}{d\lambda}=0&\phantom {10000}(1)\nonumber
\end{align}##\Gamma_{\mu\nu}^\sigma## is the Christoffel symbol (torsion-free and metric compatible)
\begin{align}
\Gamma_{\mu\nu}^\sigma=\frac{1}{2}g^{\sigma\rho}\left(\partial_\mu g_{\nu\rho}+\partial_\nu g_{\rho\mu}-\partial_\rho g_{\mu\nu}\right)&\phantom {10000}(2)\nonumber
\end{align}In this case the indices are 0,1 and ##x^0=\phi## the colatitude (angle from north pole), ##\ x^1=\theta## , longitude. The metric and inverse metric are
\begin{align}
g_{\mu\nu}=\left(\begin{matrix}1&0\\0&\sin^2{\phi}\\\end{matrix}\right)\ \ ,\ \ g^{\mu\nu}=\left(\begin{matrix}1&0\\0&\sin^{-2}{\phi}\\\end{matrix}\right)&\phantom {10000}(3)\nonumber
\end{align}Those should give me equations for ## \phi,\theta## parameterized by ## \lambda##.

I now expand the second term in (1) for ## \sigma=1## and using the fact that ## \Gamma## is torsion-free (##\Gamma_{\mu\nu}^\sigma=\Gamma_{\nu\mu}^\sigma##).
\begin{align}
\Gamma_{\mu\nu}^1\frac{dx^\mu}{d\lambda}\frac{dx^\nu}{d\lambda}&=\Gamma_{00}^1\frac{dx^0}{d\lambda}\frac{dx^0}{d\lambda}+2\Gamma_{10}^1\frac{dx^1}{d\lambda}\frac{dx^0}{d\lambda}+\Gamma_{11}^1\frac{dx^1}{d\lambda}\frac{dx^1}{d\lambda}&\phantom {10000}(4)\nonumber\\

&=\Gamma_{00}^1\left(\frac{d\phi}{d\lambda}\right)^2+2\Gamma_{10}^1\frac{d\phi}{d\lambda}\frac{d\theta}{d\lambda}+\Gamma_{11}^1\left(\frac{d\theta}{d\lambda}\right)^2&\phantom {10000}(5)\nonumber
\end{align}using the metric and (2) and taking each ## \Gamma## in turn, many terms vanish because the metric components are constant or 0
\begin{align}
\Gamma_{00}^1&=\frac{1}{2}g^{1\rho}\left(\partial_0g_{0\rho}+\partial_0g_{\rho0}-\partial_\rho g_{00}\right)=g^{1\rho}\partial_0g_{0\rho}&\phantom {10000}(6)\nonumber\\

&=g^{10}\partial_0g_{00}+g^{11}\partial_0g_{01}=0&\phantom {10000}(7)\nonumber\\
2\Gamma_{10}^1&=g^{1\rho}\left(\partial_1g_{0\rho}+\partial_0g_{\rho1}-\partial_\rho g_{10}\right)=g^{1\rho}\partial_1g_{0\rho}+g^{1\rho}\partial_0g_{\rho1}&\phantom {10000}(8)\nonumber\\

&=g^{10}\partial_1g_{00}+g^{11}\partial_1g_{01}+g^{10}\partial_0g_{01}+g^{11}\partial_0g_{11}&\phantom {10000}(9)\nonumber\\

&=\frac{1}{\sin^2{\phi}}\frac{\partial}{\partial\phi}\left(\sin^2{\phi}\right)=\frac{2\sin{\phi}\cos{\phi}}{\sin^2{\phi}}=2\cot{\phi}&\phantom {10000}(10)\nonumber\\
\Gamma_{11}^1&=\frac{1}{2}g^{1\rho}\left(\partial_1g_{1\rho}+\partial_1g_{\rho1}-\partial_\rho g_{11}\right)=g^{1\rho}\partial_1g_{\rho1}-\frac{1}{2}g^{1\rho}\partial_\rho g_{11}&\phantom {10000}(11)\nonumber\\

&=g^{10}\partial_1g_{01}+g^{11}\partial_1g_{11}-\frac{1}{2}g^{10}\partial_0g_{11}-\frac{1}{2}g^{11}\partial_1g_{11}&\phantom {10000}(12)\nonumber\\

&=\frac{1}{2}\frac{1}{\sin^2{\phi}}\frac{\partial}{\partial\theta}\left(\sin^2{\phi}\right)=0&\phantom {10000}(13)\nonumber
\end{align}Putting the expressions for ## \Gamma## back into (5) we get
\begin{align}
\Gamma_{\mu\nu}^1\frac{dx^\mu}{d\lambda}\frac{dx^\nu}{d\lambda}&=2\cot{\phi}\frac{d\phi}{d\lambda}\frac{d\theta}{d\lambda}&\phantom {10000}(14)\nonumber
\end{align}Putting that back into (1) we have
\begin{align}
\frac{d^2\theta}{d\lambda^2}+2\cot{\phi}\frac{d\phi}{d\lambda}\frac{d\theta}{d\lambda}=0&\phantom {10000}(15)\nonumber
\end{align}I can use the same method to get a solution for ## \sigma=0##, but that's not relevant yet. Put together they show that lines of longitude are always geodesics as is the equator. So far so good… but

A great circle equation (which we know is a geodesic) can be written as
\begin{align}
\theta=\lambda\ \ ,\ \ \phi=\tan^{-1}{\left(\frac{C}{A\cos{\lambda}+B\sin{\lambda}}\right)}&\phantom {10000}(16)\nonumber
\end{align}where ## A,B,C## are constants depending on the start and end points. I calculated this and checked it against the slightly ambiguous Wolfram maths article at http://mathworld.wolfram.com/GreatCircle.html.

From (16) clearly
\begin{align}
\frac{d^2\theta}{d\lambda^2}=0&\phantom {10000}(17)\nonumber
\end{align}so the other term in (15) should always be zero. It is
\begin{align}
2\cot{\phi}\frac{d\phi}{d\lambda}\frac{d\theta}{d\lambda}=-2\frac{\left(B\cos{\lambda}-A\sin{\lambda}\right)\left(A\cos{\lambda}+B\sin{\lambda}\right)}{C^2+\left(A\cos{\lambda}+B\sin{\lambda}\right)^2}&\phantom {10000}(18)\nonumber
\end{align}which is not always zero! So something is wrong.
It's either
(15) which I have calculated in another way to check it or
(16) which I have also plotted and gives good results or
my differentiation of ##\frac{d\phi}{d\lambda}## which I checked with Symbolab: https://www.symbolab.com/solver/ordinary-differential-equation-calculator/?or=dym&query=%5Cfrac%7Bd%7D%7Bdx%7D(%5Carctan(%5Cfrac%7BC%7D%7BD%5Ccos(x)%2BB%5Csin(x)%7D))

Help! What has gone wrong?
On Physics Forums at https://www.physicsforums.com/threads/question-about-geodesic-on-sphere.975370/

Sunday 21 July 2019

Question on partial derivative

I am working on the geodesic equation for the surface of a sphere. While doing so I come across the partial derivative
\begin{align}
\frac{\partial}{\partial\theta}\left(\sin^2{\phi}\right)=0?&\phantom {10000}(1)\nonumber
\end{align}where ## \phi, \theta## are colatitude(angle from north pole) and longitude. I could say that the expression must vanish because ## \phi,\theta## are orthogonal. But I know thate ## \phi## is a function ## \theta##  so I could say, using the chain rule twice, that the expression is
\begin{align}
\frac{\partial}{\partial\theta}\left(\sin^2{\phi}\right)=2\sin{\phi}\cos{\phi}\frac{d\phi}{d\theta}?&\phantom {10000}(2)\nonumber
\end{align}The answer might be very obvious and simple. I think the former is correct but would like some confirmation please.

The detailed reasons for the question are given below. They include my fears about the metric.

The geodesic equation is
\begin{align}
\frac{d^2x^\sigma}{d\lambda^2}+\Gamma_{\mu\nu}^\sigma\frac{dx^\mu}{d\lambda}\frac{dx^\nu}{d\lambda}=0&\phantom {10000}(3)\nonumber
\end{align}where ## \Gamma## is the Christoffel symbol (torsion-free and metric compatible), given by
\begin{align}
\Gamma_{\mu\nu}^\sigma=\frac{1}{2}g^{\sigma\rho}\left(\partial_\mu g_{\nu\rho}+\partial_\nu g_{\rho\mu}-\partial_\rho g_{\mu\nu}\right)&\phantom {10000}(4)\nonumber
\end{align}The coordinates are  ##x^0=\phi## and ##\ x^1=\theta## and the metric and inverse metric are
\begin{align}
g_{\mu\nu}=\left(\begin{matrix}1&0\\0&\sin^2{\phi}\\\end{matrix}\right)\ \ ,\ \ g^{\mu\nu}=\left(\begin{matrix}1&0\\0&\sin^{-2}{\phi}\\\end{matrix}\right)&\phantom {10000}(5)\nonumber
\end{align}## \lambda## will parameterise a line which gives the required geodesic. First I derived what these equations mean and I get two second order differential equations involving ## \phi,\theta,\lambda##. I believe these are
\begin{align}
\frac{d^2\phi}{d\lambda^2}-\sin{\phi}\cos{\phi}\left(\frac{d\theta}{d\lambda}\right)^2=0&\phantom {10000}(6)\nonumber
\end{align}and
\begin{align}
\frac{d^2\theta}{d\lambda^2}+2\cot{\phi}\frac{d\phi}{d\lambda}\frac{d\theta}{d\lambda}=0&\phantom {10000}(7)\nonumber
\end{align}There were two ways to work these equations out. Assuming (2) (that ##{\partial f(\phi)}/{\partial\theta}\neq0##) each method gave a different answer for equation (7) unless I made a mistake, which is quite likely.

I have not yet tried to solve these equations, but I know that a geodesic on a sphere is a great circle so I can work out its equation and it can be written
\begin{align}
\theta=\lambda\ \ ,\ \ \phi=\tan^{-1}{\left(\frac{C}{A\cos{\lambda}+B\sin{\lambda}}\right)}&\phantom {10000}(8)\nonumber
\end{align}where ## A,B,C## are constants depending on the start and end points (in quite a complicated way.) It should be simple to check that (8) satisfies (6) and (7). Clearly ## \phi## depends only on ## \theta## and the start and end points, as one would expect. This leads to the original question.

I checked my equation (8) by using my wonderful 3-D plotter. The geodesics look perfect.
I also searched the internet for the equation and found one on Wolfram MathWorld (http://www.mathworld.wolfram.com/GreatCircle.html). It was slightly different from mine and cause me great pain. It is incorrect! Their colatitudes and latitudes are mixed up. I have told them, but there is no response. I also plotted their solution and it gave a rather long route to Peking. Whatever the case ## \phi## depends on ## \theta## and the start and end points.

(8) tells us that
\begin{align}
\frac{d^2\theta}{d\lambda^2}=0&\phantom {10000}(9)\nonumber
\end{align}Which does not sit well with (7). If I had the metric at (5) 'the wrong way round', it would be
\begin{align}
g_{\mu\nu}=\left(\begin{matrix}\sin^2{\phi}&0\\0&1\\\end{matrix}\right)\ \ ,\ \ g^{\mu\nu}=\left(\begin{matrix}\sin^{-2}{\phi}&0\\0&1\\\end{matrix}\right)&\phantom {10000}(10)\nonumber
\end{align}this would have given (9) at (7). However I want to cross one bridge at a time …

Posted on PF at https://www.physicsforums.com/threads/question-on-partial-derivative.975058/

The first three answers satisfy me that$$
\frac{\partial}{\partial\theta}\left(\sin^2{\phi}\right)=0
$$Equation (8) is just the equation of some line on the sphere, in this case a geodesic.

MS-Word macros for equations and more

Since I have got a new computer and Office 365 (upgrading from Office 2007), I have been taking advantage of the new features. In particular the ability to switch to Latex equations is great and I have used it and been able to stop using GrindEQ. I have written a completely new macro to generate web pages containing Latex. Sadly, there seems to be no way to determine in Word VBA whether equations are in Latex or Unicode mode. This must be done by hand. Also sadly, if Latex mode is always turned on, variables such as ##x,\phi## come out as non italic. This is disliked by mathematicians.

This is an update of older posts like this one in Tools. I will recap and add in the new stuff.

This post has three main sections
1) Equations in MS-Word
2) Converting a Word document to something suitable for a web page.
3) Getting the macros

1) Equations in MS-Word

I had been copying and pasting tables and equations in MS-Word for far too long, so I wrote some word macros to speed things up. I can now easily produce correctly aligned equations like
Fig 1: Aligning equation numbers neatly using 2 x 1 tables
and
Fig 2: LHS of equations unchanged and aligning equation numbers
I now have a "Quick access toolbar", part of it is like this

From the left, they have the following effects
  1. Select table (MS-Word command)
  2. Outside border on selected table Macro: BordersOutside
  3. Remove all borders from table Macro: BordersNone
  4. Add all borders to table Macro: BordersAll
  5. 0.8 cm row height on selected rows Macro: Point8cmTableRows
  6. (##\pi##) Insert inline equation (font size 12). Macro: InsertEquationInLine
  7. Insert unbarred 2 x 1 table with centred justified equation in column 1, (nn) in column 2 (Fig 1). Macro: EquationTable2
  8. Insert unbarred 3 x 1 with right justified equation in column 1, left justified equation in column 2 and (nn) in column 3 (Fig 2) Macro: EquationTable3
  9. Renumber all equations Macro: aaRenumberEquations
The first five are useful for quickly sorting problems with tables and tidying them. With 7 & 8, the equation number (nn) is one bigger than the last one up the document. The one line tables are inserted according to customary MS-Word rules. There are three constants in the macros which may be adjusted to suit your taste:
  • EquationFontSize - default 12 points 
  • TableHeight - height of new equation rows in cm, default 1.29
  • EquationColumnWidth - column width in cm of equation number column, default 1.38 
It often happens that you need to insert a few extra equations in the middle of a document. Here's a tip: Insert the first equation which will probably have the same number as the equation below. Change its number to 100 (or another large number). Following equations will be numbered 101, 102, ... When you have finished adding the group, renumber all equations. Which brings us to the next macro.

aaRenumberEquations

Obviously after a bit of copying and pasting or writing things out of order, equation numbers can become a mess. For this we have the aaRenumberEquations macro which just renumbers all the equations from 1-n. It also adjusts all the references to said equations. Equation numbers such as a, b, b123,  2.5 will be renumbered.

I have tested it on the .docx which produced Commentary 1.1 Tensors matrices and indexes.pdf . It contains 213 equations numbers and 154 references to them. It took 112 seconds. The macro estimates the time that will be taken at the beginning (92 seconds in this case) and gives suitable warnings if it is more than 40 seconds. Clearly the overall time will depend on the machine.

aaRenumberEquations detects two kinds of error:

1) There is a reference to an equation that does not exist and the reference number would become a new equation number. In this case you get an error like
Equation (4) is referenced. It does not exist.
2) Equations are numbered with the same number twice or more and that number is used as an equation reference. (It does not matter if duplicate equation numbers are used but they are not referenced). In this case you get an error like
Equation (33) is defined 3 times and referenced one or more times.
Progress, and all errors found are displayed in another window.

I now activate this macro from the Quick access tool bar because it is robust and I use it often.
I used to only activate it from the Macros button, which is in the View and Developer ribbons, which explains the aa in the name.

It is now possible to create Word documents containing beautifully numbered equation and created .pdf files from them for example. What about a web page or a long question with equation numbers on Physics Forums? That brings us to the final macro which I use rarely and therefore only activate from the Macros button.

2) aPrepareForWeb 

aPrepareForWeb creates a new window and copies unformatted text and Latex equations from the current document into the new window. Latex equation mode must be switched on in Word. As stated above, there seems to be no way to determine in Word VBA whether equations are in Latex or Unicode mode.  aPrepareForWeb uses $$ for display and ## for inline Latex equation delimiters. These can easily be changed. They are the same as Physics Forums. Obviously the host website must deal with these delimiters and Latex. An example MathJax script, used on this website, is at MathJaxSnippet.txt.

aPrepareForWeb also treats tables as if they contained equations with equation numbers in the last column. It uses the Latex environment begin{align} .. end{align} (backslashes omitted here!) and other gizmos to produce aligned equations for a website. This has the unfortunate side effect that genuine word tables can get destroyed! The remedy is obvious.

There is a file for demonstrating and testing the converter here: aPrepareForWeb conversion tester.docx.

3) Getting the macros

The macros are in Word VBA. If you would like to use these macros click here to see every version. Open the most recent then copy and paste into the Visual Basic editor, Normal / Modules, on the Developer tab. That will save them in Normal.dotm. (If you can't see the developer tab in the 'Ribbon', search for developer in your Word help. It's version dependent.) To run the macros you may also need to 'Trust access to the VBA project object model' in the Word Trust Center Settings.

If you have any questions, just leave a comment or email me.

Thursday 11 July 2019

Penrose tiles - a program to build Penrose tilings

Here's a free program for drawing Penrose tiles (tessellations) with PowerPoint.

Add, snap, deflate, inflate, grow, shrink and format kites and darts with it. It is very easy to use and the functions allow you to rapidly create huge numbers of tiles properly arranged. Record to date is 22,523 tiles.

If the toolbox is enlarged, buttons to label tile vertices and produce a report on the slide also become available. The box at the bottom gives information and sometimes error messages.

To get the program just download the macro enabled PowerPoint file here (0.8 Mb) and open it. Macros must be enabled and the first slide  contains instructions how to get started. There are another four slides which contain interesting ready-made patterns and some useful info.

The program was implemented in Microsoft PowerPoint VBA and tested on Office 365.

There is more on this site about Penrose tiles here and full documentation on the program here (10 Mb). It contains some big pictures and the proof of why the ratio of the sides of kites and darts is the golden ratio is ##\phi## where $$\phi=\frac{1+\sqrt5}{2}$$This formula was known to the ancient Greeks and appears in many mathematical formulas. I have not seen a proof of this for Penrose tiles anywhere else. It is always just stated as if it was obvious.