Peeter Joot's (OLD) Blog.

Math, physics, perl, and programming obscurity.

Archive for March, 2014

Found code that fails grade 11 math: log base conversion.

Posted by peeterjoot on March 26, 2014

Unless my headache is impacting my ability to manipulate log identities, this LOG10 code is plain wrong:

      static double findLog(double value, FunctionType logFunction)
      {
         switch (logFunction)
         {
            case LN:
               return log(double(value));
            case LOG10:
               return log(double(value)) / log(2.0);
...
      }

Perhaps it is dead code, since this divide should be log(10.0) (or just M_LN10), but nobody appears to have noticed.

Two other possibilities are:

  • somebody was being way too clever, and when they wrote LOG10, they meant it as Log base 0b10.
  • somebody thought that for computer software a “natural logarithm” would use base 2.

Posted in C/C++ development and debugging. | Tagged: , , | 2 Comments »

Herring salad recipe from Dad’s papers

Posted by peeterjoot on March 12, 2014

This was a favorite of my dad, Jaan Joot.  I’m pretty sure that it is actually Vanaema’s recipe.

 

2 herring

2 small cans beets

6 potatoes (large)

4-5 pickles

1 onion

1 apple

3 (¼”) slides ham or 5” kolbassa

2 hard boiled eggs

1 tablespoon mustard

salt and pepper to taste

sour cream and mayo (small bowl)

– add above just before serving

Makes about 3-4 liters.

Posted in reciepes | 1 Comment »

Curvilinear coordinates and reciprocal basis

Posted by peeterjoot on March 9, 2014

[Click here for a PDF of this post with nicer formatting]

Motivation

Here I’d like to explore some ideas from [1] where curvilinear coordinates, manifolds, and the vector derivative are introduced.

Notation

For simplicity, let’s consider the concrete example of a 2D manifold, a surface in an n dimensional vector space, parameterized by two variables

\begin{aligned}\mathbf{x} = \mathbf{x}(a,b) = \mathbf{x}(u^1, u^2).\end{aligned} \hspace{\stretch{1}}(1.2.1)

Note that the indices here do not represent exponentiation. We can construct a basis for the manifold as

\begin{aligned}\mathbf{x}_i = \frac{\partial {\mathbf{x}}}{\partial {u^i}}.\end{aligned} \hspace{\stretch{1}}(1.2.2)

On the manifold we can calculate a reciprocal basis \{\mathbf{x}^i\}, defined by requiring, at each point on the surface

\begin{aligned}\mathbf{x}^i \cdot \mathbf{x}_j = {\delta^i}_j.\end{aligned} \hspace{\stretch{1}}(1.2.3)

Associated implicitly with this basis is a curvilinear coordinate representation defined by the projection operation

\begin{aligned}\mathbf{x} = x^i \mathbf{x}_i,\end{aligned} \hspace{\stretch{1}}(1.2.4)

(sums over mixed indexes are implied). These coordinates can be calculated by taking dot products with the reciprocal frame vectors

\begin{aligned}\mathbf{x} \cdot \mathbf{x}^i &= x^j \mathbf{x}_j \cdot \mathbf{x}^i \\ &= x^j {\delta_j}^i \\ &= x^i.\end{aligned} \hspace{\stretch{1}}(1.2.4)

Examples

Let’s pause for a couple examples that have interesting aspects.

Example: Circular coordinates on a disk

Consider an infinite disk at height z_0, with the origin omitted, parameterized by circular coordinates as in fig. 1.1.

Fig 1.1: Plane with circular coordinates

 

Points on this surface are

\begin{aligned}\mathbf{x}(r, \theta) = (r \cos\theta, r \sin\theta, z_0).\end{aligned} \hspace{\stretch{1}}(1.3.6)

The manifold basis vectors, defined by eq. 1.2.2 are

\begin{aligned}\begin{aligned}\mathbf{x}_r &= (\cos\theta, \sin\theta, 0) \\ \mathbf{x}_\theta &= r (-\sin\theta, \cos\theta, 0).\end{aligned}\end{aligned} \hspace{\stretch{1}}(1.3.7)

By inspection, the reciprocal basis is

\begin{aligned}\begin{aligned}\mathbf{x}^r &= (\cos\theta, \sin\theta, 0) \\ \mathbf{x}^\theta &= \frac{1}{{r}} (-\sin\theta, \cos\theta, 0).\end{aligned}\end{aligned} \hspace{\stretch{1}}(1.3.8)

The first thing to note here is that we cannot reach the points \mathbf{x} of eq. 1.3.6 by linear combination of these basis vectors. Instead these basis vectors only allow us to reach other points on the surface, when already there. For example we cannot actually write

\begin{aligned}\mathbf{x} = x^r \mathbf{x}_r + x^\theta \mathbf{x}_\theta,\end{aligned} \hspace{\stretch{1}}(1.3.9)

unless z_0 = 0. This is why eq. 1.2.4 was described as a projective operation (and probably deserves an alternate notation). To recover the original parameterized form of the position vector on the surface, we require

\begin{aligned}\mathbf{x} = x^r \mathbf{x}_r + x^\theta \mathbf{x}_\theta + z_0 \hat{\mathbf{z}}.\end{aligned} \hspace{\stretch{1}}(1.3.10)

The coordinates x^r, x^\theta follow by taking dot products

\begin{aligned}x^r &= \mathbf{x} \cdot \mathbf{x}^r \\ &= (r \cos\theta, r \sin\theta, z_0) \cdot(\cos\theta, \sin\theta, 0) \\ &= r \left( \cos^2 \theta + \sin^2 \theta \right) \\ &= r\end{aligned} \hspace{\stretch{1}}(1.0.11.11)

\begin{aligned}x^\theta &= \mathbf{x} \cdot \mathbf{x}^\theta \\ &= (r \cos\theta, r \sin\theta, z_0) \cdot\frac{1}{{r}} (-\sin\theta, \cos\theta, 0) \\ &= 0.\end{aligned} \hspace{\stretch{1}}(1.0.11.11)

Therefore, a point on the plane, relative to the origin of the plane, in this case, requires just one of the tangent plane basis vectors

\begin{aligned}\mathbf{x} = r \mathbf{x}_r.\end{aligned} \hspace{\stretch{1}}(1.0.11.11)

Example: Circumference of a circle

Now consider a circular perimeter, as illustrated in fig. 1.2, with the single variable parameterization

Fig 1.2: Circular perimeter

 

\begin{aligned}\mathbf{x} = r_0 \left( \cos\theta, \sin\theta \right).\end{aligned} \hspace{\stretch{1}}(1.13)

Our tangent space basis is

\begin{aligned}\mathbf{x}_\theta = r_0 \left( -\sin\theta, \cos\theta \right),\end{aligned} \hspace{\stretch{1}}(1.14)

with, by inspection, a reciprocal basis

\begin{aligned}\mathbf{x}^\theta = \frac{1}{{r_0}} \left( -\sin\theta, \cos\theta \right).\end{aligned} \hspace{\stretch{1}}(1.15)

Here we have a curious condition, since the tangent space basis vector is perpendicular to the position vector for the points on the circular surface. So, should we attempt to calculate coordinates using eq. 1.2.4, we just get zero

\begin{aligned}x^\theta &= \mathbf{x} \cdot \mathbf{x}^\theta \\ &= r_0 \left( \cos\theta, \sin\theta \right) \cdot\frac{1}{{r_0}} \left( -\sin\theta, \cos\theta \right) \\ &= 0.\end{aligned} \hspace{\stretch{1}}(1.16)

It’s perhaps notable that a coordinate representation using the tangent space basis is possible, but we need to utilize a complex geometry. Assuming

\begin{aligned}\mathbf{x} = x^\theta \mathbf{x}_\theta,\end{aligned} \hspace{\stretch{1}}(1.17)

and writing i = \mathbf{e}_1 \mathbf{e}_2 for the pseudoscalar, we can write

\begin{aligned}\begin{aligned}\mathbf{x} &= r_0 \mathbf{e}_1 e^{i\theta} \\ \mathbf{x}_\theta &= r_0 \mathbf{e}_2 e^{i\theta},\end{aligned}\end{aligned} \hspace{\stretch{1}}(1.18)

so that, by inversion, the \theta coordinate is

\begin{aligned}x^\theta &= \mathbf{x}\frac{1}{{\mathbf{x}_\theta}} \\ &= \left( r_0 \mathbf{e}_1 e^{i\theta} \right)\left( \frac{ e^{-i\theta } \mathbf{e}_2 }{r_0} \right) \\ &= i,\end{aligned} \hspace{\stretch{1}}(1.19)

or

\begin{aligned}\mathbf{x} = i \mathbf{x}_\theta.\end{aligned} \hspace{\stretch{1}}(1.0.20)

Example: Surface of a sphere

It is also clear that any parameterization that has radial symmetry will suffer the same issue. For example, for a radial surface in 3D with radius r_0 we have

\begin{aligned}\begin{aligned}\mathbf{x} &= r_0 \left( \sin\theta \cos\phi, \sin\theta \sin\phi, \cos\theta \right) \\ \mathbf{x}_\theta &= r_0 \left( \cos\theta \cos\phi, \cos\theta \sin\phi, -\sin\theta \right) \\ \mathbf{x}_\phi &= r_0 \left( -\sin\theta \sin\phi, \sin\theta \cos\phi, 0 \right) \\ \mathbf{x}^\theta &= \frac{1}{{r_0}} \left( \cos\theta \cos\phi, \cos\theta \sin\phi, -\sin\theta \right) \\ \mathbf{x}^\phi &= \frac{1}{{r_0 \sin\theta}} \left( -\sin\phi, \cos\phi, 0 \right).\end{aligned}\end{aligned} \hspace{\stretch{1}}(1.0.21)

The reciprocals here were computed using the mathematica reciprocalFrameSphericalSurface.nb notebook.

Do we have a bivector parameterization of the surface using the tangent space basis? Let’s try

\begin{aligned}\mathbf{x} = x^\theta \mathbf{x}_\theta + x^\phi \mathbf{x}_\phi.\end{aligned} \hspace{\stretch{1}}(1.0.22)

Wedging with \mathbf{x}_\theta and \mathbf{x}_\phi, and writing i = \mathbf{e}_1 \mathbf{e}_2, respectively yields

\begin{aligned}x^\theta &= \mathbf{x} \wedge \mathbf{x}_\phi \frac{1}{{\mathbf{x}_\theta \wedge \mathbf{x}_\phi}} \\ &= -\mathbf{e}_1 \mathbf{e}_3 \cos \phi - \mathbf{e}_2 \mathbf{e}_3 \sin \phi \\ &= \mathbf{e}_{31} e^{ i \phi}.\end{aligned} \hspace{\stretch{1}}(1.0.22)

\begin{aligned}x^\phi &= -\mathbf{x} \wedge \mathbf{x}_\theta \frac{1}{{\mathbf{x}_\theta \wedge \mathbf{x}_\phi}} \\ &= \mathbf{e}_1 \mathbf{e}_3 \cot \theta \sin \phi + i -\mathbf{e}_2 \mathbf{e}_3 \cot \theta \cos \phi \\ &= \mathbf{e}_2 \mathbf{e}_3 \cot \theta e^{i \phi} + i.\end{aligned} \hspace{\stretch{1}}(1.0.22)

However, substitution back into eq. 1.0.22 shows either pair parameterizes the radial position vector

\begin{aligned}\mathbf{x} = x^\theta \mathbf{x}_\theta = x^\phi \mathbf{x}_\phi.\end{aligned} \hspace{\stretch{1}}(1.0.25)

It is interesting that duality relationships seem to naturally arise attempting to describe points on a surface using the tangent space basis for that surface.

References

[1] A. Macdonald. Vector and Geometric Calculus. CreateSpace Independent Publishing Platform, 2012.

Posted in Math and Physics Learning. | Tagged: , , , | Leave a Comment »