Attitude matrix and quaternion path for m>1

I noticed that somehow I did not finish with the case $m>1.$ So today, without further ado, I am posting the algorithm.
We have the body with $I_11/I_2$, where $d$ is, as always, the ratio of the doubled kinetic energy to angular momentum squared.
Then we define

A_2&=&\sqrt{\frac{I_2 (1-dI_1)}{I_2-I_1}},\\
A_3&=&\sqrt{\frac{I_3 (1-dI_1)}{I_3-I_1}},\\
\psi(t)=\frac{t}I_3-\arctan\left((A_2/A_1)\mathrm{sd}(Bt,\mu) \right)+\alpha \Pi(\nu,\am(Bt,\mu),\mu),\

I use the above formulas to draw a stereographic projection of one particular path. So, I take $I_1=1,I_2=2,I_3=3,d=0.5000001$, and do the parametric plot of the curve $\mathbf{r}(t)$ in $\mathbf{R}^3,$
I show below two plots. One with $t\in(-1000,1000),$ and one with $t\in(-10000,10000).$ For this selected value of $d,$ the time between consecutive flips, given by the formula
\begin{equation}\tau =4\mathrm{EllipticK}(\mu)/B= 116.472.\end{equation}
So, for $t\in(-10000,10000)$ we have somewhat less than 200 flips, and the lines are getting rather densely packed in certain regions.
Notice that is just one geodesic line, geometrically speaking the straightest possible line in the geometry determined by the inertial properties of the body.

It is this “geometry”that will become the main subject of the future notes.

Geodesic line for t between -1000 and 1000

Geodesic line for t between -10000 and 10000

How can such a line be “straight”? Well, it is….

Attitude matrix for m<1

The last post was about The final answer for the Universe in which m>1. Yet, as I see it today, it was neither complete nor final. It was a very bad approximation. It may be also that our universe is also a very bad approximation to the one that has been intended. But that is another story. I think I will return to this problem in my blogging, but now I will concentrate on the algorithm for the rotation matrix. At the same time I will make a comment how the algorithm from the last post, for the quaternions, should be improved. The fact is that I was making wrong assumptions in my mind. Making wrong assumptions, without being conscious of the fact that one is making such assumptions, that is very dangerous. Lot of bad things happens around us for this reason….

Plane crash
The result of wrong assumptions

So, here is the code:

The case $m<1.$ The solution $\mathbf{L}(t)$ of the Euler's equations has two trajectories. For one with $L_3(t)>0$ we take
A_1&=&\sqrt{\frac{I_1 (d I_3-1)}{I_3-I_1}},\\
A_2&=&\sqrt{\frac{I_2 (d I_3-1)}{I_3-I_2}},\\
A_3&=&\sqrt{\frac{I_3 (1-d I_1)}{I_3-I_1}},\\
while for the other one, with $L_3(t)<0$ we take \begin{eqnarray} A_1&=&-\sqrt{\frac{I_1 (d I_3-1)}{I_3-I_1}},\\ A_2&=&\sqrt{\frac{I_2 (d I_3-1)}{I_3-I_2}},\\ A_3&=&-\sqrt{\frac{I_3 (1-d I_1)}{I_3-I_1}}.\\ \end{eqnarray} Let \begin{eqnarray} B&=&\sqrt{\frac{(1-d I_1) (I_3-I_2)}{I_1 I_2 I_3}},\\ m&=&\frac{(d I_3-1) (I_2-I_1)}{(1-d I_1) (I_3-I_2)}. \end{eqnarray} The solution $\mathbf{L}(t)$ of the Euler's equations is given by \begin{eqnarray} L_1(t)&=&A_1\, \cn (Bt,m),\\ L_2(t)&=&A_2\, \sn (Bt,m),\\ L_3(t)&=&A_3\, \dn (Bt,m), \end{eqnarray} With constants $\alpha$ and $\nu$ defined as \begin{equation} \alpha=\frac{I_3-I_1}{\sqrt{\frac{I_1(1-d I_1)(I_3-I_2)I_3}{I_2}}}, \end{equation} \begin{equation} \nu=\frac{I_1-dI_1I_3}{I_3-dI_1I_3} \end{equation} we set the phase variable $\psi(t)$ as \begin{equation} \psi(t)=\frac{t}I_1+\arctan\left((A_2/A_3)\mathrm{sd}(Bt,m) \right)-\alpha \Pi(\nu,\am(Bt,m),m),\ \end{equation} where the Jacobi function $\mathrm{sd}$ is defined as $\mathrm{sd}(u,m)=\sn(u,m)/\dn(u,m).$ Let \begin{equation} \begin{equation} Q_1(t) =\begin{bmatrix} L_1(t)& L_2(t)& L_3(t)\\-L_2(t)& 1 - \frac{L_2(t)^2}{1 + L_1(t)}& -\frac{L_2(t) L_3(t)}{1 + L_1(t)}\\ -L_3(t)& -\frac{L_2(t) L_3(t)}{1 + L_1(t)}& 1 - \frac{L_3(t)^2}{1 + L_1(t)},\end{bmatrix} \end{equation} \begin{equation} Q_2(t)=\begin{bmatrix} 1 & 0 & 0 \\ 0 & \cos \psi (t) & -\sin \psi (t) \\ 0 & \sin \psi (t) & \cos \psi (t) \\ \end{bmatrix}. \end{equation} Then the attitude matrix $Q(t)$ is given by \begin{equation}Q(t)=Q_2(t)Q_1(t).\end{equation}

If you compare this with the formulas I gave yesterday, you will find the following important difference: now I am playing with signs in the constants $A_1,A_3$ rather than with the signs in formulas for $L_1(t),L_3(t).$ It took me whole day to realize that this way is a better way. I was not realizing before that there is one sign in the formula for $\psi(t)$ that depends on the trajectory we are taking. The constant $A_2/A_3$ does this job now.

In a couple of days I will also change the formulas in the quaternionic algorithm to make them universal as well.

Now, I check the modified example3. The modified initial data in init_example3.dat file are as follows:
They are the same as in the quaternionic case discussed yesterday. The initial attitude matrix is the identity matrix. We get the same $t_0.$ I use Mathematica to calculate the transposed final $Q$

Transpose[Inverse[Q[t0]].Q[t0 + 10.0]]
{{0.0656754, 0.550118, -0.832501}, {0.995487, 0.0211483,
0.0925082}, {0.0684964, -0.834819, -0.546246}}

We compare it with the Fortran output from 903 code:


And it seems that our code is doing the same job as the Fortran code from the giants!
Yet, as I said at the beginning, it took me the whole days to figure it out why for some initial data I was in agreement, but for another initial data there was a disagreement.

There is one little plus of the code above. The coefficient in front of $\arctan$ is fixed, and equal $1.$! Zanna and Celledoni in their paper and in their code have complicated formulas for this coefficient. It would take some work to verify that their complicated formula simplifies to $1.$ I hope I am right here….

The final answer for the Universe in which m<1

This is not an independent post or note or whatever. It is a continuation. In fact it is the continuation of Approaching the ultimate answer for m<1. We have approached enough. We are ready.

There was a moment’s expectant pause while panels slowly came to life on the front of the console. Lights flashed on and off experimentally and settled down into a businesslike pattern. A soft low hum came from the communication channel.
“Good morning,” said Deep Thought at last.
“Er … good morning, O Deep Thought,” said Loonquawl nervously, “do you have … er, that is …”
“An answer for you?” interrupted Deep Thought majestically. “Yes. I have.”
The two men shivered with expectancy. Their waiting had not been in vain.
“There really is one?” breathed Phouchg.
“There really is one,” confirmed Deep Thought.

Douglas Adams, The Hitchhiker’s Guide to the Galaxy

We did not get to the answer yesterday, but today is the day. We will be using the formulas from the last post. Here they are again, repeated for your convenience:

The case $m<1.$ \begin{eqnarray} A_1&=&\sqrt{\frac{I_1 (d I_3-1)}{I_3-I_1}},\\ A_2&=&\sqrt{\frac{I_2 (d I_3-1)}{I_3-I_2}},\\ A_3&=&\sqrt{\frac{I_3 (1-d I_1)}{I_3-I_1}},\\ B&=&\sqrt{\frac{(1-d I_1) (I_3-I_2)}{I_1 I_2 I_3}},\\ m&=&\frac{(d I_3-1) (I_2-I_1)}{(1-d I_1) (I_3-I_2)}. \end{eqnarray} The solution $\mathbf{L}(t)$ of the Euler's equations has two trajectories: one with $L_3(t)>0$ is given by
L_1(t)&=&A_1\, \cn (Bt,m),\\
L_2(t)&=&A_2\, \sn (Bt,m),\\
L_3(t)&=&A_3\, \dn (Bt,m),
while the other one, with $L_3(t)<0$ is given by \begin{eqnarray} L_1(t)&=&-\,A_1\, \cn (Bt,m),\\ L_2(t)&=&A_2\, \sn (Bt,m),\\ L_3(t)&=&-\,A_3\, \dn (Bt,m).\label{eq:3} \end{eqnarray} With constants $\alpha$ and $\nu$ defined as \begin{equation} \alpha=\frac{I_3-I_1}{\sqrt{\frac{I_1(1-d I_1)(I_3-I_2)I_3}{I_2}}}, \end{equation} \begin{equation} \nu=\frac{I_1-dI_1I_3}{I_3-dI_1I_3} \end{equation} we set the phase variable $\psi(t)$ as \begin{equation} \psi(t)=\frac{t}I_1-\arctan\left((A_2/A_3)\mathrm{sd}(Bt,m) \right)-\alpha \Pi(\nu,\am(Bt,m),m),\ \end{equation} where the Jacobi function $\mathrm{sd}$ is defined as $\mathrm{sd}(u,m)=\sn(u,m)/\dn(u,m).$ Then the quaternionic attitude solution is given by $q(t)=W(t)+\mathbf{i}X(t)+\mathbf{j}Y(t)+\mathbf{k}Z(t),$ with \begin{eqnarray} W(t)&=&\cos \frac{\psi(t)}{2}\sqrt{\frac{1+L_1(t)}{2}},\\ X(t)&=&\sin \frac{\psi(t)}{2}\sqrt{\frac{1+L_1(t)}{2}},\\ Y(t)&=&\frac{L_3(t)\cos \frac{\psi(t)}{2}+L_2(t)\sin \frac{\psi(t)}{2}}{\sqrt{2(1+L_1(t))}},\\ Z(t)&=&\frac{-L_2(t)\cos \frac{\psi(t)}{2}+L_3(t)\sin \frac{\psi(t)}{2}}{\sqrt{2(1+L_1(t))}}\label{eq:5} \end{eqnarray}

We consider Example Four with



$m_3(0)$ is negative, the therefore we take option as in Eq. \ref{eq:3}). We calculate $t_0$ that reproduces the initial angular momenta. The method is known from the previous posts:

So we have $t_0.$ At $t=t_0$ our angular momentum is the same as angular momentum in example 4 at $t=0.$ We calculate $q_0=q(t_0)$ from Eq'(\ref{eq:5})
We verify that we have indeed a unit quaternion:
Thus the inverse quaternion is the same as conjugated one:
In the Example 4 the initial quaternion, at $t=0$ is $1$. Therefore in order for our solution to reproduce the initial data of the example we set
The final time in Example 4 is $t=10.$ Therefore we calculate
where the multiplication is the quaternion multiplication.
Calculated with Mathematica the answer is
The result from the Fortran code in the file out_example4.dat is


It seems that therefore that we have obtained the ultimate answer. At least for quaternions. We need to get it also for rotation matrices. So the saga will continue.