# Metric Tensor in Quantity System

The best part in making the Quantity System, is that I am re-discovering mathematics with it. It gives me an immense pleasure to learn mathematics in a practical way and to try and make corrections on two levels, Programming and Mathematics.

This post will be a usage scenario for the quantity system. The scenario will be applicable for the latest source code (which can be downloaded from http://quantitysystem.codeplex.com/SourceControl/list/changesets labeled by version [Qs 1.2.5])

In this post I will explain the mathematical foundation with my language/realization (so I am not tied to the formal way of books)

# Coordinates Introduction

In studying geometry, we always encounter (*x,y,z*) coordinate system. This system simply is a way to describe the **location of point**.

And if we are talking with **Vectors**, then {*x y z*} is an arrow coming from {0 0 0} to {*x y z*} and we are calling it **Vector**.

Using {*x _{1} x_{2} x_{3}*} labeling instead of {

*x y z*} then we have indexes 1,2, and 3 usually referred as R

^{3}Space.

What does that mean ??

R^{2}: 2 dimensional coordinate system (2D Space)

R^{3}: 3 dimensional coordinate system (3D Space)

R^{4}: 4 dimensional coordinate system (4D Space) (yes it exists somehow refer to Hypersphere coordinate system http://en.wikipedia.org/wiki/N-sphere )

Note: Using ‘R’ refer to the numbering system type we are using which is Real Numbers.

So in R^{n} the point/vector can be described by {*x _{1} x_{2} x_{3} x_{4}* ..

*x*} and to generalize the point location we end into defining

_{n}

*x*_{i}where *i*: 1,2, 3, .., *n* for number of coordinates

## Cartesian Coordinates

They are simply {*x y*} or {*x y z*}, R^{2} or R^{3} which we all know and studied during school. (an important note here is that the angle between the unit vectors is 90 degree or Orthogonal)

## Curvilinear Coordinates

In this type of coordinates the unit vectors that represent the coordinate system is not a straight forward lines, but on contrary they are making curves in some way.

When dealing with curvilinear coordinates every coordinate has a **tangent vector** (e) and **orthogonal vector** (E)

Without going into a lot of details these extra vectors are the foundation of covariant and contravariant vectors

The curse of Curvilinear coordinates is that the location of point can be represented by two vectors covariant or contravariant.

We label the two types of vectors by this

Contravariant vector: x^{i} superscript index or simple {x^{1} x^{2} x^{3}}

Covariant vector: x_{i} subscript index {x_{1} x_{2} x_{3}}

Best to be seen by the following figure

Note: we are obliged to use two types of vectors specially when we are beginning to use geometric properties of geometric objects (for example the line length in curvilinear coordinates is not the same as Cartesian coordinates, think about line over spherical object like big line on earth) line length = sqrt(x*x + y*y + z*z) however in curvilinear length = sqrt(x_{1}*x^{1} + x_{2}*x^{2} +x_{3}*x^{3}) or simply length = sqrt(x_{i}*x^{i}) Einstein summation notation.

## Coordinates Transformation

We can transform the point from Cylindrical to Cartesian (here I mean changing the representation of point/vector from r,q,z to x,y,z )

x = r cos(q)

y = r sin(q)

z = z

a vice versa transformation exist but I will not write it here

for simplicity let us write that any {r q z} vector we can transform it by multiplying it with {r*cos(q) r*sin(q) z}

so for any two coordinate systems there is a transformation

Note: in mathematical books they are referring to Jacobian calculation to make sure that such transformation exist

How can we make this simple with quantity system?

- Define a vector that contains a symbolic quantities
- Get the function from this vector
- Now you can get x, y, z vector from r q z vector by the function fc
- Also using named parameters (so you don’t get ambiguous about parameters order)
- And for fun you can pass Symbolic parameters (remember that quantity system blend the usage between numbers and symbols)

Note: Quantity system permits you to make calculations on symbols as if they were first citizen types in Qs to define symbol you can precede dollar sign before it like $x $y $myvariable and to define complex expression you can use ${expression} like ${x+y*r} or ${sqrt(sin(u*v^2))} please refer to the separate symbolic variable engine that also made by me in http://symbolicalgebra.codeplex.com

## Covariant and Contravariant vectors Dilemma

A question is raised here, how can I get covariant and contravariant components of vector with the guide of Transformation Equations and existing vector?

This dilemma is solved by the Metric Tensor. The metric tensor is a matrix like object that when multiplied by vector gets the corresponding vector

There are also two types of metric tensor (covariant metric tensor and contravariant metric tensor)

To calculate the metric tensor we get back to the definition of base vector

In the figure above the x^{1},x^{2},x^{3} represent a curvilinear coordinate system and g_{1},g_{2},g_{3} represent covariant base vectors (the base vectors has been defined by the differentiation of the location point transformation of curvilinear coordinate system)

Let us take the cylindrical transformation to Cartesian

x = r cos(q)

y = r sin(q)

z = z

g_{1} = g_{1x}*i_{1}+g_{1y}*i_{2}+g_{1z}*i_{3}

to get these components we differentiate each term of transformation vector with r

g_{1x} = diff(r*cos(q), r)

g_{1y} = diff(r*sin(q), r)

g_{1z} = diff(z, r)

then we get the other

g_{2} also is the differentiation of all components with q

g_{3} is differentiating with z

Now to make the metric tensor we will use the **dot product** of vectors to get this 2^{nd} order tensor which looks like matrix

g |
g |
g |

g |
g |
g |

g |
g |
g |

I will not dive into details about characteristics of metric tensor but there are common rules about them

- contravariant * covariant metric tensors = Identity
- Covariant Metric Tensor * Covariant Vector = Contravariant Vector
- Contravariant Metric Tensor * Contravariant Vector = Covariant Vector.

So by getting the metric tensor for the curvilinear coordinate system (or any higher spaces if we want) then we can get the covariant and contravariant components of vector.

# Metric Tensor with Quantity System

As my reader can see, you have to know many skills to get the metric tensor for specific coordinate system

- Transformation equations
- Differentiations
- Dot Product
- Matrix Algebra (for matrix inverse)

Without another mumbling let’s use the precious quantity system for this operation.

Continuing on the last transformation for cylindrical coordinates

- Get g
_{1} - as it can be noticed differentiation has been made all over components of vector
- Get g
_{2} - Get g
_{3 } - Get the covariant metric tensor

You can notice that if you do *Trigonometric simplification* to the covariant metric tensor of cylindrical coordinates would be

1 |
0 |
0 |

0 |
r |
0 |

0 |
0 |
1 |

Which is the right deduction for it (I didn’t implement simplification in symbolic algebra yet bear with me please J)

## Calculating contravariant vector

- Get a function from the metric tensor
- Suppose that we have vector with r=3 theta=2 and z=10 as a covariant vector
- Then to get contravariant vector we simply do the following

Conclusion:

- Quantity system make it easy to calculate the metric tensor
- Quantity system make it easy to get covariant and contravariant vectors
- I am very biased J

J to the quantity system (I can’t help it actually)

Of course I am not claiming that my implementation is 100% error free (and you will see mistakes while playing with these calculations) however I am trying to say that the idea of blending symbolic calculations beside numerical calculations and getting the result easily and intuitively should enhance the global or macro view of mathematics and may increase the researcher ability to distinguish between these concepts and testing it easily while he is studying.

I also wish that I can reach a stable state that makes these calculations really reachable and easy for all of those interested beside being easy in using as an embedded language inside C# applications and .NET framework.

Thank you all for reading this so far.

Ahmed Sadek

## Trackbacks & Pingbacks