Sunday, March 19, 2017

Portland to New York Using only Gravity (Part 3)

Portland to New York Using only Gravity (Part 3) Here we are at part 3 of a series of posts relating to an "underground brachistochone" where we wish to build a tunnel for a train propelled only by gravity from Portland, Oregon to New York, New York.

We left off in part 2 with the computation of the time to traverse the tunnel equal to $$ \Delta t = \pi \sqrt{\frac{R^2 - r_0^2}{gR}} $$ Of course, this requires us to know the depth of the tunnel but we were able to compute the time as a function of a fraction of the earth's radius, \(R\). What we want is a way to compute the depth of the tunnel, \(r\) as a function of the angle we're at or vice versa.

To start this process, we recall, from part 2 $$ \begin{equation} \theta' = \frac{1}{r}\sqrt{\frac{\frac{k^2g}{R}(R^2-r^2)}{r^2-\frac{k^2g}{R}(R^2-r^2)}} \label{eq:tp} \end{equation} $$ and recalling our definition of \(r_0\) stemming from solving for the conditions at the curve minimum $$ \begin{equation} \frac{k^2g}{R} = \frac{r_0^2}{R^2-r_0^2} \label{eq:r0} \end{equation} $$ Substuting \ref{eq:r0} into \ref{eq:tp} gives us, after a little bit of algebra, $$ \begin{equation} d\theta = \frac{1}{r}\sqrt{\frac {r_0^2(R^2-r^2)} {R^2(r^2-r_0^2)} }dr \label{eq:dt} \end{equation} $$ Moving some constants out of the way helps, sometimes, so lets do $$ \begin{equation} \frac{R}{r_0}d\theta = \frac{1}{r}\sqrt{\frac {R^2-r^2} {r^2-r_0^2} }dr \label{eq:dt2} \end{equation} $$ If you were to enter \ref{eq:dt2} into Wolfram-Alpha you would get a hot mess in return. Wolfram-Alpha is really, really smart but sometimes a little trickery is required to bend the integrand into something that it finds more recognizable. To that end, let $$ u^2 = \frac{r^2-r_0^2}{R^2-r^2} $$ This is kind of strange but making \(u\) equal to the upside-down-integrand kind of makes sense as the derivative of a square root is 1-over-the-square-root (multiplied by the derivative of the ... radicand ... it's been a while, is that right)? Solving for \(r^2\), $$ r^2 = \frac{u^2R^2 + r_0^2}{1+u^2} $$ Now we find \(dr\) but instead of taking the square root and differentiating, we will differentiate implicitly. $$ \eqalign { 2rdr &= {{2R^2u(1+u^2) - 2u(u^2R^2+r_0^2)} \over {(1+u^2)^2}}du \cr &= {{2u(R^2+r_0^2)} \over {(1+u^2)^2}}du \cr dr &= \frac{u}{r}{{(R^2+r_0^2)} \over {(1+u^2)^2}}du } $$ This will get a little messy but hang in there. First off, notice that $$ u=\sqrt{\frac{r^2 - r_0^2}{R^2-r^2}} $$ so $$ \frac{1}{u}=\sqrt{\frac{R^2-r^2}{r^2 - r_0^2}} $$ which is the most of the original integrand. Working our way through this $$ \eqalign { \frac{R}{r_0}\theta = \int\frac{1}{r}\sqrt{\frac {R^2-r^2} {r^2-r_0^2} }dr &= \int\frac{1}{r}\frac{1}{u}\frac{u}{r}\frac{R^2-r_0^2}{(1+u^2)^2}du \cr &= \int\frac{1}{r^2}\frac{R^2-r_0^2}{(1+u^2)^2}du \cr \text{(substituting for } r^2 \text{)} &= \int\frac{1+u^2}{(u^2R^2+r_0^2)}\frac{R^2-r_0^2}{(1+u^2)^2}du \cr &= \int\frac{R^2-r_0^2}{(u^2R^2+r_0^2)(1+u^2)}du \cr } $$ That last integrand looks like a job for partial fractions. $$ \eqalign { \frac{R^2-r_0^2}{(u^2R^2+r_0^2)(1+u^2)} &= \frac{A}{u^2R^2+r_0^2} + \frac{B}{1+u^2} \cr R^2-r_0^2 &= A(1+u^2) + B(u^2R^2+r_0^2) \cr &= u^2(A+BR^2) + A + Br_0^2 \cr \therefore A=R^2, B=-1 } $$ Putting this back into the integral $$ \begin{equation} \eqalign{ \frac{R}{r_0}\theta &= \int\frac{R^2-r_0^2}{(u^2R^2+r_0^2)(1+u^2)}du = R^2\int\frac{du}{u^2R^2+r_0^2} - \int\frac{du}{1+u^2} \cr &= \frac{R}{r_0}\tan^{-1}\left(\frac{Ru}{r_0}\right) - \tan^{-1}u + C \cr \theta &= \tan^{-1}\left(\frac{R}{r_0} \sqrt{\frac{r^2 - r_0^2}{R^2-r^2}} \right) - \frac{r_0}{R}\tan^{-1}\sqrt{\frac{r^2 - r_0^2}{R^2-r^2}} + C\cr } \end{equation} $$ Here we let \(\theta(r_0) = 0 \rightarrow C = 0\). At the surface, when \(r = R\), we can compute that $$ \theta = \frac{\pi}{2} - \frac{r_0}{R}\frac{\pi}{2} $$ $$ \begin{equation} \theta = \frac{\pi}{2} (1 - \frac{r_0}{R}) \label{eq:thetaR} \end{equation} $$ The angle \(\theta(R)\) in \ref{eq:thetaR} is the angle from where the curve is the deepest to the surface. So, given that the tunnel will travel from the surface down to the minimum then back up again, the total span, \(\Psi\), of the tunnel is $$ \Psi = 2\theta = \pi (1 - \frac{r_0}{R}) $$ And solving for \(r_0\) $$ \begin{equation} r_0 = R(1 - \frac{\Psi}{\pi}) \label{eq:r0x} \end{equation} $$ The earth's radius in kilometers is \(R=6371\text{km}\). The flight distance from PDX to JFK is \(d=3949\text{km}\). Since \(d=R\Psi\) the required angle spanned by this distance is \(\Psi = \frac{d}{R} = \frac{3949}{6371} = 0.62\). $$ \eqalign { \Psi &= 0.62 \cr r_0 &= R(1 - \frac{\Psi}{\pi}) = 6371(1 - \frac{0.62}{\pi}) = 5114\text{ km} \cr } $$ And from part 2 of this series, the time \(\Delta t\) is given by (remember to adjust the units!) $$ \eqalign { \Delta t &= \pi \sqrt{\frac{R^2 - r_0^2}{gR}} \cr &= \pi \sqrt{\frac{6371000^2 - 5114000^2}{(9.8)(6371000)}} \cr &\approx 25 \text{ minutes} } $$ We can also ask about the maximum speed attained. Since we've declared that the sum of the kinetic and potential energy are zero and that this is true for the entire traversal of the path, we can deduce that the kinetic energy is at a maximum where the potential energy is at a minimum. This happens at \(r=r_0\). We saw from part one of this series that $$ \eqalign { |v| &= \sqrt{\frac{g}{R}(R^2-r^2)} \cr &= \sqrt{\frac{9.8}{6371000}(6371000^2 - 5114000^2)} \cr &\approx 4713 \frac{\text{m}}{\text{s}} \cr &\approx 16970 \frac{\text{km}}{\text{hr}} } $$ So there you have it... How long is the tunnel? How many Gs are being generated at \(r=r_0\). I'll leave those for the reader.

Friday, March 10, 2017

Underground from Portland to New York (Part 2)

Underground from Portland to New York (Part 2) This post is part two of what will be a three part series on the derivation of the equations of an underground tunnel that minimizes travel time when only gravity is used for propulsion. We left our subterranean tunnel problem with the following equation we wished to minimize. $$ \eqalign{ I &= \int_a^b\frac{\sqrt{(dr)^2+(rd\theta)^2}}{\sqrt{\frac{g}{R}(R^2-r^2)}} } $$ Our first issue is figuring out what to do with \(\sqrt{(dr)^2+(rd\theta)^2}\) so that we can integrate it. We could choose to factor out either the \(dr\) or the \(d\theta\) and could solve the problem either way. We'll choose to factor out the \(dr\) because that leaves us an integrand that is not a function of the path variable (in this case \(\theta\)) which means that \(\pard{F}{\theta} = 0\) and \(\pard{F}{\theta'} = constant\). So, we have the Euler-Lagrange equation for this problem (remember that \(r\) is our variable of integration): $$ \eqalign{ \frac{d}{dr}\pard{F}{\theta'} - \pard{F}{\theta} = 0 \cr \text{but}\enspace \pard{F}{\theta} = 0 \cr \text{therefore}\enspace \frac{d}{dr}\pard{F}{\theta'} = 0 \cr \text{so}\enspace \pard{F}{\theta'} = k } $$ $$ \pard{}{\theta'} \left(\frac{\sqrt{1+(r\theta')^2}}{\sqrt{\frac{g}{R}(R^2-r^2)}}\right) = k $$ Performing the differentiation we have $$ \frac{1}{\sqrt{\frac{g}{R}(R^2-r^2)}}\cdot\frac{r^2\theta'}{\sqrt{1+(r\theta')^2}} = k $$ Squaring both sides and solving for \((r\theta')^2\) first $$ \frac{1}{\frac{g}{R}(R^2-r^2)}\cdot\frac{(r^2\theta')^2}{1+(r\theta')^2} = k^2 $$ $$ \begin{equation} \frac{\frac{k^2g}{R}(R^2-r^2)}{r^2-\frac{k^2g}{R}(R^2-r^2)} = (r\theta')^2 \label{eq:rt2} \end{equation} $$ We solve for \((r\theta')^2\) and mark that equation because in the end, our original integral for the minimum time is a function of \((r\theta')^2\) and we don't want to have to recompute it. Going the final step to solve for \(\theta'\) we have $$ \begin{equation} \theta' = \frac{1}{r}\sqrt{\frac{\frac{k^2g}{R}(R^2-r^2)}{r^2-\frac{k^2g}{R}(R^2-r^2)}} \label{eq:tp} \end{equation} $$ At this point we pause to consider the variable and limits of integration. If you look at the figure below, we can see that to traverse the curve, \(r\) goes from \(R\) to \(R\). That doesn't help us much because the definite integral would end up being 0.
We do notice, however, that the curve must be symmetric (the path shouldn't matter on which side you start) and so the deepest part of the curve is in the middle at \(r_0\). At this value of \(r=r_0\), we can see that \(\frac{dr}{d\theta} = 0\) since \(r(\theta)\) is mimimized. Conversely, this means that \(\theta' = \frac{d\theta}{dr} \rightarrow \infty\). This happens when the denominator of equation \ref{eq:tp} becomes zero. So, solving for the constants in this case when \(r=r_0\) $$ r_0^2 - \frac{k^2g}{R}(R^2-r_0^2) = 0 $$ yields $$ \frac{k^2g}{R} = \frac{r_0^2}{R^2-r_0^2} $$ Before we find the path, we'll find the time it takes to traverse the curve. Of course, this time will be a function of \(r_0\) so we will still have some work to do. Rewriting equation \ref{eq:rt2} with the above substitution and then cleaning up some of the fractions yields $$ (r\theta')^2 = \frac{\frac{r_0^2}{R^2-r_0^2}(R^2-r^2)}{r^2-\frac{r_0^2}{R^2-r_0^2}(R^2-r^2)} $$ yields $$ \begin{equation} (r\theta')^2 = \frac{r_0^2(R^2-r^2)}{r^2(R^2-r_0^2)-r_0^2(R^2-r^2)} \label{eq:rt2r0} \end{equation} $$ Now, going back to our original functional we factor out the \(dr\) and put in the actual limits of integration, multiplying the whole thing by 2 because we're only going halfway in the integral. $$ \Delta t = 2\int_{R}^{r_0}\frac{\sqrt{1+(r\theta')^2}}{\sqrt{\frac{g}{R}(R^2-r^2)}}dr $$ Substituting \ref{eq:rt2r0} into the above and moving some constants over to the left hand side $$ \frac{1}{2}\sqrt{\frac{g}{R}}\Delta t = \int_{R}^{r_0}\frac{1}{\sqrt{(R^2-r^2)}}\cdot\frac{r\sqrt{R^2-r_0^2}}{\sqrt{r^2(R^2-r_0^2) - r_0^2(R^2-r^2)}}dr $$ And after a little more algebra, factoring out the \((R^2-r_0^2)\) $$ \frac{1}{2}\sqrt{\frac{g}{R}}\Delta t = \int_{R}^{r_0}\frac{r}{\sqrt{(R^2-r^2)(r^2 - \frac{r_0^2}{R^2-r_0^2}(R^2-r^2))}}dr $$ Sometimes at points like this it helps to look at the units to make sure we at least have a sanity check. On the left hand side we have \(\sqrt{\frac{m}{s^2}\cdot\frac{1}{m}}\cdot s\) which is unitless. On the right, we have \(\frac{m\cdot m}{\sqrt{m^4}}\) which is also unitless. So we at least have that going for us. We're almost home for this part. We now have a relatively straightforward integration. We let \(u=R^2-r^2\), \(du = -2rdr\) and \(r^2 = R^2 - u\). These substitutions result in $$ \frac{1}{2}\sqrt{\frac{g}{R}}\Delta t = -\frac{1}{2}\int_{R}^{r_0}\frac{1}{\sqrt{u((R^2-u) - \frac{r_0^2}{R^2-r_0^2}u)}}dr $$ Simplifying the denominator $$ \frac{1}{2}\sqrt{\frac{g}{R}}\Delta t = -\frac{1}{2}\int_{R}^{r_0}\frac{1}{\sqrt{u(R^2-(1+\frac{r_0^2}{R^2-r_0^2})u)}}dr $$ A little more $$ \frac{1}{2}\sqrt{\frac{g}{R}}\Delta t = -\frac{1}{2}\int_{R}^{r_0}\frac{1}{\sqrt{u(R^2-\frac{R^2}{R^2-r_0^2}u)}}dr $$ A little more algebra by factoring out an \(R^2\) from the to get the integral into a more recognizable form $$ \frac{1}{2}\sqrt{\frac{gR^2}{R}}\Delta t = -\frac{1}{2}\int_{R}^{r_0}\frac{1}{\sqrt{u(1 - \frac{1}{R^2-r_0^2}u)}}dr $$ Simplifying the left a little and with a little help from Wolfram-Alpha we have (putting back the \(u=R^2-r^2\)) $$ \eqalign { \frac{1}{2}\sqrt{gR}\Delta t &= 2\sqrt{(R^2-r_0^2)}\sin^{-1}\left(\sqrt{\frac{R^2-r^2}{R^2-r_0^2}}\right) \Bigg \bracevert_R^{r_0} \cr \frac{1}{2}\sqrt{gR}\Delta t &= 2\sqrt{(R^2-r_0^2)}(\frac{\pi}{2} - 0) \cr \frac{1}{2}\sqrt{gR}\Delta t &= \pi\sqrt{R^2-r_0^2} } $$ And finally solving for \(\Delta t\) $$ \Delta t = 2 \pi \sqrt{\frac{R^2 - r_0^2}{gR}} $$ Here, we can ask the question of how long will it take to go from one side of the earth to the other, straight through the core. At that point, \(r_0 = 0\) so \(\Delta t = 2\pi\sqrt{\frac{R}{g}} \). With \(g=9.8\frac{\text{m}}{\text{s}^2}\) and the radius of the earth \(R=6.4\cdot10^6 \text{m}\) $$ \Delta t = 2\pi\sqrt{\frac{6.4\cdot 10^6}{9.8}} \approx 5078 \text{s} \approx 85 \text{min} $$ Here is a graph of the transit time in minutes versus the depth as a fraction of \(R\).
Solving for the path is coming in part 3.

Saturday, March 4, 2017

Underground from Portland to New York (Part 1)

Portland to New York Using only Gravity (Part 1)

The Brachistochrone

The brachistochrone is a classic problem put forth by Johann Bernoulli and solved by some of the mathematical heavyweights of the day. The basic premise of the problem is that given two points connected by a curve, find the shape of the curve such that a particle moving only under the influence of gravity would travel along the curve in the minimum time. Somewhat surprisingly, this curve is not a straight line. Even Galileo figured this out in 1638 though mistakenly thought the curve was a circular arc. It turns out that the curve is a cycloid but that's not what we're going to prove here.

Going Underground

Lets say we want to build a transportation tunnel from Portland, Oregon to New York, New York. We've invented a frictionless surface and we can evacuate the tunnel so there won't be any air resistance. We want to go completely green and only use gravity for travel. Oh, and to add to our perfectly realistic assumptions, we live on an earth of uniform density and of perfectly spherical shape.

What is the shape of the tunnel that will get us across in the shortest amount of time?

In similar fashion to solving the Brachistochrone problem, we must minimize the functional $$ I=\int_{t0}^{t1}dt = \int_a^b \frac{ds}{v} $$

To get started we'll employ some basic physics. Because there is no energy added to the system, the sum of kinetic and potential energies will be a constant throughout the trip. The kinetic energy, \(T\), is familiar and we can write it directly as $$ T = \frac{1}{2}m_Tv^2 $$ where \(m_T\) is the mass of the train. The potential energy, \(V\), is not quite as straightforward as it is not the familiar \(V=mgh\) we've seen in our entry level physics class. To derive it we first need to find the forces involved. The force of gravity is $$ \vec{F} = -G\frac{m_Em_T}{r^2} \uvec{r} $$ where \(m_E\) is the effective mass of the earth when we are somewhere inside of it at a distance \(r\) from the center. This mass is all the mass that is located less than or equal to a distance \(r\) from the center. So $$ m_E = \frac{4}{3}\rho\pi r^3 $$ where \(\rho\) is the (uniform!) density of the earth. Plugging that back into our force equation gives $$ \vec{F} = -G\frac{\left(\frac{4}{3}\rho\pi r^3\right)m_T}{r^2} \uvec{r} = -\frac{4}{3}G\rho\pi m_T r \uvec{r} $$ (Note the negative sign since the force is directed opposite the radial direction.) Since we know the acceleration due to gravity is \(g = 9.8 \frac{m}{s^2} \) at the surface, \(r = R\) we make the substutition of $$ \eqalign{ g &= \frac{4}{3}G\pi\rho R \cr \vec{F} &= -\frac{m_T g}{R}r\uvec{r} } $$ As an aside, here it is interesting to note that inside the earth, the force actually increases linearly with the distance \(r\). This is because the mass increases as \(r^3\) even though the gravity is an inverse-square law.

Now to compute the integral for potential energy, we will choose our reference (\(V=0\)) point to be \(r = R\). The line integral is along the radius to a distance \(r\) from the center. $$ V = -\int_R^r -\frac{m_T g}{R} x dx = \frac{m_Tg}{2R}(r^2 - R^2) $$ Since the total energy \(T+V=0\) at the start and no energy is added to the system we can set the total energy to 0 and solve for the speed as a function of \(r\). $$ \eqalign{ T+V &= \frac{1}{2}m_Tv^2 + \frac{m_Tg}{2R}(r^2 - R^2) = 0 \cr v &= \sqrt{\frac{g}{R}(R^2-r^2)} } $$ We are now at a point where we can write the functional we wish to minimize as $$ \eqalign{ I &= \int_{t0}^{t1}dt = \int_a^b \frac{ds}{v} \cr &= \int_a^b\frac{\sqrt{(dr)^2+(rd\theta)^2}}{\sqrt{\frac{g}{R}(R^2-r^2)}} } $$ To be continued in part deux.

Monday, February 27, 2017

Derivation of Divergence in Cylindrical Coordinates

Derivation of Divergence in Cylindrical Coordinates $$ \newcommand{\pard}[2]{\frac{\partial #1}{\partial #2}} $$ $$ \newcommand{\vec}[1]{\boldsymbol{#1}} $$ $$ \newcommand{\unitv}[1]{\boldsymbol{\hat{#1}}} $$ The divergence of a vector field in Cartesian coordinates is fairly straight forward: $$ \nabla\cdot \vec{F} = \pard{F_x}{x} + \pard{F_y}{y} + \pard{F_z}{z} $$ But before we undertake this derivation, it will help to try and understand the meaning of divergence. It is tempting to just take the partial derivatives in whatever coordinate system you're using and add them together. But alas, this doesn't quite work.

First, let us consider flux.

Flux is the amount of something passing through a surface multiplied by the area of that surface. It can be a fluid, gas, electric field, or anything that can be described by a vector field. In the picture below, there are F liters/minute of water flowing in the circular pipe.

If we were to consider an imaginary surface slicing perpendicularly through the pipe (surface A), the flux through that circular surface would be F liters/minute multiplied by the area of the circle. It is important to note that that if we were to consider a surface slicing through at a bias (like surface B), the flux would be the same. Even though the elliptical area is larger than the circular one the amount of flux per unit area is less because the flux is no longer perpendicular to the surface. Flux through an area is then defined as $$ \Psi = \vec{F}\cdot\vec{A} = \|\vec{F}\|\|\vec{A}\|\cos\theta $$ where the vector area \( \vec{A} \) is defined to be normal to the surface. For a surface that is open, the choice of which of the two normal vectors we mean is arbitrary (we just have to be consistent). For a closed surface, the normal is defined to point to the outside of the surface. The angle \(\theta\) is the angle between the area-normal and the vector \(\vec{F}\). You can see as the angle between the flow and the surface gets closer to \(\frac{\pi}{2}\) that the flux gets smaller and smaller until it vanishes completely when the two are perpendicular.

Now, consider the volume defined by surfaces A, B and the walls of the pipe in the figure above. We can define the total flux through the volume as $$ \Psi_{total} = \Psi_{pipe} + \Psi_A + \Psi_{B} $$ Unless we have a leaky pipe, \(\Psi_{pipe} = 0\). Because we define the surface normal of a closed surface to point outward, the flux through surface A is negative (the flow and the normal are in opposite directions, so the dot-product is negative). The flow through B is equal in magnitude to that passing through surface B but positive. Hence, \(\Psi_{total} = 0 \). This makes intuitive sense when dealing with conservation of mass as otherwise there would be an accumulation of mass inside the pipe (\(\Psi_{total} < 0\)) or loss of mass (\(\Psi_{total} > 0\)).

Divergence is the amount of flux leaving a closed surface as the volume of the closed surface approaces zero. So, we now look at the general sitution of the pipe above in cylindrical coordinates. We consider a small enough closed volume that we can consider it a cube. In order to compute the total flux, we have to do 6 integrations as there are 6 sides to a cube. But we will group them in pairs, one pair for each direction \(\rho, \phi, z\).

The vector field in cylindrical coordinates is given by $$ \vec{F} = F_{\rho} \unitv{\rho} + F_{\phi} \unitv{\phi} + F_{z} \unitv{z} $$ We place our tiny cube-like volume in the field \(\vec{F}\) at some point \(\vec{P}=(\rho,\phi,z)\).

First we consider the flux passing through the surfaces normal to the \(z\) direction (the top and bottom faces of the cube). Since the distances involved are small, we can approximate the field passing through these as $$ F_{top} = F_z(\rho,\phi,z + \Delta z) \approx F_z(\rho,\phi,z) + \pard{F_z}{z}(\rho,\phi,z)\frac{\Delta z}{2} $$ It should be noted that the other components of the field don't play a part here because they are parallel to these surfaces so nothing going in the, say, \(\rho\) direction leaves via the \(z\) direction. Similarly for the bottom surface, $$ F_{bottom} = F_z(\rho,\phi,z - \Delta z) \approx F_z(\rho,\phi,z) - \pard{F_z}{z}(\rho,\phi,z)\frac{\Delta z}{2} $$ The areas of these surfaces are equal and independent of \(z\). $$ A_z = \rho\Delta\phi\Delta\rho $$ Therefore, the flux through these z-surfaces is (remembering that the flux through the bottom surface is into the volume and so is negative) $$ \Psi_z = F_{top}A_z - F_{bottom}A_z = (F_{top} - F_{bottom})A_z $$ $$ \Psi_z = (F_z + \pard{z}{F_z}\frac{\Delta z}{2} - (F_z - \pard{F_z}{z}\frac{\Delta z}{2}))\rho\Delta\phi\Delta\rho $$ $$ \Psi_z = \pard{F_z}{z}\rho\Delta \phi \Delta\rho \Delta z $$ Recognize that the term \( \rho\Delta \phi \Delta\rho \Delta z \) is the differential volume in cylindrical coordinates, so we can write the previous equation as $$ \begin{equation} \label{eq:fluxz} \Psi_z = \pard{F_z}{z}\Delta V \end{equation} $$ Where \(\Delta V\) is the differential volume element. I should note that if you were to do this derivation in Cartesian coordinates, the x and y component derivations would be identical (except for the subscripts). But in cylindrical coordinates, things get a little more interesting from here on out. Looking now at the \(\phi\) direction we consider the front and back faces of the volume. (I will omit the function arguments to the partial derivatives in the service of brevity with the understanding that we are talking about the point \(P=(\rho,\phi,z)\)). $$ F_{back} = F_\phi(\phi + \Delta \phi) \approx F_\phi + \pard{F_\phi}{\phi}\frac{\Delta \phi}{2} $$ $$ F_{front} = F_\phi(\phi - \Delta \phi) \approx F_\phi - \pard{F_\phi}{\phi}\frac{\Delta \phi}{2} $$ $$ A_\phi = \Delta\rho\Delta z $$ Because the positive \(\phi\) direction is toward the back of the volume, $$ \Psi_{\phi} = (F_{back} - F_{front})A_{\phi} $$ $$ \Psi_{\phi} = (F_\phi + \pard{F_\phi}{\phi}\frac{\Delta \phi}{2} - (F_\phi - \pard{F_\phi}{\phi}\frac{\Delta \phi}{2}))\Delta\rho\Delta z $$ $$ \Psi_{\phi} = \pard{F_\phi}{\phi}\Delta\phi\Delta\rho\Delta z $$ The term \(\Delta\phi\Delta\rho\Delta z\) is almost the differential volume. And maybe because we know where we are headed, we bend the equation to our will $$ \Psi_{\phi} = \pard{F_\phi}{\phi}\Delta\phi\Delta\rho\Delta z = \pard{F_\phi}{\phi}\frac{\rho}{\rho}\Delta\phi\Delta\rho\Delta z $$ $$ \begin{equation} \label{eq:fluxphi} \Psi_\phi = \frac{1}{\rho}\pard{F_\phi}{\phi}\Delta V \end{equation} $$ Now we try to handle the \(\rho\) component. We need to be careful here. But first things first. The vector field is defined similarly to previous components. $$ F_{right} = F_\rho(\rho + \Delta \rho) \approx F_\rho + \pard{F_\rho}{\rho}\frac{\Delta \rho}{2} $$ $$ F_{left} = F_\phi(\rho - \Delta \rho) \approx F_\rho - \pard{F_\rho}{\rho}\frac{\Delta \rho}{2} $$ Here is where it gets tricky. The area definitions are different because the two surfaces are not equal in size and so must be treated differently. $$ A_{right} = (\rho+\frac{\Delta\rho}{2})\Delta\phi\Delta z $$ $$ A_{left} = (\rho-\frac{\Delta\rho}{2})\Delta\phi\Delta z $$ First computing the flux on the right side. $$ \Psi_{right} = F_{right}A_{right}=(F_\rho + \pard{F_\rho}{\rho}\frac{\Delta \rho}{2})((\rho+\frac{\Delta\rho}{2})\Delta\phi\Delta z) $$ $$ \Psi_{right} = (F_\rho + \pard{F_\rho}{\rho}\frac{\Delta \rho}{2})(\rho\Delta\phi\Delta z + \frac{1}{2}\Delta\rho\Delta\phi\Delta z) $$ $$ \Psi_{right} = F_\rho\rho\Delta\phi\Delta z+\frac{1}{2}F_\rho\Delta\rho\Delta\phi\Delta z + \frac{1}{2}\pard{F_\rho}{\rho}\rho\Delta\rho\Delta\phi\Delta z + \frac{1}{4}\pard{F_\rho}{\rho}\Delta\rho^2\Delta\phi\Delta z $$ Similarly on the left hand side $$ \Psi_{left} = F_{left}A_{left}=(F_\rho - \pard{F_\rho}{\rho}\frac{\Delta \rho}{2})((\rho-\frac{\Delta\rho}{2})\Delta\phi\Delta z) $$ $$ \Psi_{left} = (F_\rho - \pard{F_\rho}{\rho}\frac{\Delta \rho}{2})(\rho\Delta\phi\Delta z - \frac{1}{2}\Delta\rho\Delta\phi\Delta z) $$ $$ \Psi_{left} = F_\rho\rho\Delta\phi\Delta z-\frac{1}{2}F_\rho\Delta\rho\Delta\phi\Delta z - \frac{1}{2}\pard{F_\rho}{\rho}\rho\Delta\rho\Delta\phi\Delta z + \frac{1}{4}\pard{F_\rho}{\rho}\Delta\rho^2\Delta\phi\Delta z $$ Computing \(\Psi_\rho\) (finally, after all that algebra) by subtracting and cancelling terms $$ \Psi_\rho = \Psi_{right} - \Psi_{left} $$ $$ \Psi_\rho = F_\rho\Delta\rho\Delta\phi\Delta z + \pard{F_\rho}{\rho}\rho\Delta\rho\Delta\phi\Delta z $$ We make the same modification to the first term that we did with \(\Psi_\phi\) and substituting \(\Delta V\) $$ \begin{equation} \label{eq:fluxrho} \Psi_\rho = \frac{1}{\rho}F_\rho\Delta V + \pard{F_\rho}{\rho}\Delta V \end{equation} $$ This last equation is correct but we normally don't see it written this way, so we factor out a \(\frac{1}{\rho}\) and invoke the reverse chain rule. $$ \Psi_\rho = \frac{1}{\rho}(F_\rho + \rho\pard{F_\rho}{\rho})\Delta V = \frac{1}{\rho}\pard{}{\rho}(\rho F_\rho)\Delta V $$ And so the total flux through our tiny volume is $$ \Psi_{total} = \Psi_\rho + \Psi_\phi + \Psi_z = \left(\frac{1}{\rho}\pard{}{\rho}(\rho F_\rho) + \frac{1}{\rho}\pard{F_\phi}{\phi} + \pard{F_z}{z}\right)\Delta V $$ The divergence is the ratio of the flux through a closed surface as the volume of that closed surface approaces 0. $$ \nabla\cdot\vec{F} = \lim\limits_{\Delta V \to 0} \frac{\Psi_{total}}{\Delta V} = \frac{1}{\rho}\pard{}{\rho}(\rho F_\rho) + \frac{1}{\rho}\pard{F_\phi}{\phi} + \pard{F_z}{z} $$

The derivation of divergence in spherical coordinates procedes along similar lines as the \(\phi\) and \(\rho\) terms. It's a little more complicated because of the added \(\sin\theta\) terms.

Tuesday, February 21, 2017

Geodesic on a Plane in Polar Coordinates

Geodesic on a Plane in Polar Coordinates This is a simple problem in the calculus of variations where we prove that the shortest distance between two points is a straight line. But, instead of the normal Cartesian coordinate system, we will use polar coordinates \( \left( r, \phi \right) \). Some people use \( \theta \) for the angle but to be consistent with the cylindrical and spherical coordinate nomenclature, I choose to use \( \phi \). I was somewhat stumped at the end because there is a difficult integral to evaluate but we'll cross that bridge when we get to it.

In typical fashion, we wish to minimize the functional $$ I = \int_a^b ds $$ And the first thing we need to do is figure out what \( ds \) is. Looking at the figure below,

we can see that the differential length of the curve is the hypotenuse of the right triangle (well, not quite a triangle but it approaches one as \(d\phi \rightarrow 0\)) and is given by $$ ds = \sqrt{dr^2 + (rd\phi)^2} $$ In order to get something we can integrate, we have a decision to make: we need to decide which differential to factor out of the radical and integrate by either \(dr\) or \(d\phi\). Do we go with $$ ds = \sqrt{\left(\frac{dr}{d\phi}\right)^2 + r^2} d\phi $$ or $$ ds = \sqrt{1 + (r\frac{d\phi}{dr})^2} dr $$ In order to decide, we need to look at the Euler-Lagrange equation knowing that the \(F\) in the equation is the integrand in our functional. $$ F = F(x,y,y') : \frac{d}{dx}\left(\frac{\partial F}{\partial y'}\right) - \frac{\partial F}{\partial y} = 0 $$ The equation becomes significantly simpler to solve if we can choose an integrand that is not a function of the middle argument, i.e. a function only of the independent variable and the derivative. If this is the case, then \(\frac{\partial F}{\partial y} = 0 \) leaving the first term to be 0 as well. If the first term is 0, then inner partial derivative must be a constant because the derivative of a constant is 0. $$ \frac{\partial F}{\partial y'} = K $$ In our case,that leads us to use the second equation $$ ds = \sqrt{1 + (r\frac{d\phi}{dr})^2} dr = \sqrt{1 + (r\phi')^2} dr $$ because the first form contains a dependency on \(r\) as well as \(r'\).

So we now have to solve $$ F = F(r,\phi,\phi') : \frac{\partial F}{\partial \phi'} = \frac{\partial}{\partial \phi'}\left(\sqrt{1 + (r\phi')^2}\right) = K $$ Taking the partial derivative with respect to \(\phi'\), we have $$ {{r^2\phi'} \over \sqrt{1 + r^2\phi'^2}} = K $$ Squaring both sides gives $$ {{r^4\phi'^2} \over {1 + r^2\phi'^2}} = K^2 $$ Then $$ {r^4\phi'^2} = K^2 \left( 1 + r^2\phi'^2 \right) $$ and solving for \(\phi'2\) gives us $$ \phi'^2 = \frac{K^2}{r^2\left( r^2 - K^2 \right)} $$ Taking the square root and moving \( dr \) to the right side, gives $$ d\phi = \frac{K}{r\sqrt{ r^2 - K^2 }}dr $$ So, here is where it got tricky for me. If you type the above integral into Wolfram-Alpha you'll get something ridiculously complicated. If you're smarter than me, you might be able to simplify it but I had to look at this integral for a while before I came up with an answer. The trick with this stuff is knowing what spell to cast.

Whenever you see square-roots with squares and quotients, think right-triangles.

You can see that the \( \frac{K}{\sqrt{r^2 - K^2}} \) term is \(\tan \alpha\). So, we make that substitution giving us $$ d\phi = \frac{\tan \alpha}{r} dr $$ Now, what do we do about the \( r \)? Well, looking at the triangle, $$ \sin \alpha = \frac{K}{r} $$ This also means that $$ r = K\csc \alpha $$ so $$ dr = -K\cot(\alpha) \csc(\alpha) d\alpha $$ Making those substitutions leaves us with $$ d\phi = \frac{1}{K}\frac{K}{r}\tan(\alpha)dr = -\frac{1}{K}\sin(\alpha)\tan(\alpha)K\cot(\alpha)\csc(\alpha)d\alpha $$ And lo and behold, the entire thing becomes $$ d\phi = -d\alpha $$ which is something even I can solve. $$ \phi = -\alpha + C $$ Solving for \(\alpha\) in terms of \(r\), $$ \sin(\alpha) = \frac{K}{r} \Rightarrow \alpha = \sin^{-1}(\frac{K}{r}) $$ Plugging this back into our result gives us $$ \phi = -\sin^{-1}\left(\frac{K}{r}\right) + C $$ $$ \sin(C-\phi) = \frac{K}{r} $$ $$ r\sin(C-\phi) = K $$ If you don't recognize the above as a line in polar coordinates, we can go one step further using the sin-of-the-sum-of-angles identity $$ r\left(\sin(C)\cos(\phi)-\cos(C)\sin(\phi)\right) = K $$ and gathering up constants, we are left with $$ Ar\cos(\phi) + Br\sin(\phi) = K $$ and since \(x = r\cos(\phi), y = r\sin(\phi)\) are the transformations for polar to Cartesian coordinates $$ Ax + By = K $$ which is the general form of a line in Cartesian coordinates.

It's always satisfying to see something work out.