Quaternions

Let $a$, $b$, $c$, $d$ be real numbers, the quaternion is an expression in the form \[ a+b\mathbf{i}+c\mathbf{j}+d\mathbf{k} \] where $\mathbf{i}$, $\mathbf{j}$, $\mathbf{k}$ plays the role as $i$ does in complex numbers. Their multiplications are shown in the table below. \[ \begin{array}{|c|rrrr|} \hline * & 1 & \mathbf{i} & \mathbf{j} & \mathbf{k} \\ \hline 1 & 1 & \mathbf{i} & \mathbf{j} & \mathbf{k} \\ \mathbf{i} & \mathbf{i} & -1 & \mathbf{k} & -\mathbf{j} \\ \mathbf{j} & \mathbf{j} & -\mathbf{k} & -1 & \mathbf{i} \\ \mathbf{k} & \mathbf{k} & \mathbf{j} & -\mathbf{i}& -1 \\ \hline \end{array} \] The multiplication of quaternions is not commutative; that exists quaternions $x_1$ and $x_2$ such that $x_1x_2$ and $x_2x_1$ are different.

With this application we can add, substract, multiply, and divide quaternions. The following 12 functions are also supported.

function description/example
$\mathrm{abs}(x)$ If $x=a+b\mathbf{i}+c\mathbf{j}+d\mathbf{k}$, this function return $\sqrt{a^2+b^2+c^2+d^2}$
$\mathrm{conj}(x)$ If $x=a+b\mathbf{i}+c\mathbf{j}+d\mathbf{k}$, this function return $a-b\mathbf{i}-c\mathbf{j}-d\mathbf{k}$
$\mathrm{sqrt}(x)$ the square root of quaternion $x$
$\mathrm{pow}(x,r)$ or $x\hat{\;} r$ Calculate $x^r$, where $x$ is a quaternion and $r$ is a real number. Undefined if $r$ is a quaternion.
$\exp(x)$ The base-e exponential function of quaternion $x$
$\log(x)$ The natural logarithm function of quaternion $x$
$\sin(x)$ The sine function of quaternion $x$
$\cos(x)$ The cosine function of quaternion $x$
$\tan(x)$ The tangent function of quaternion $x$
$\sinh(x)$ The hyperbolic sine function of quaternion $x$
$\cosh(x)$ The hyperbolic cosine function of quaternion $x$
$\tanh(x)$ The hyperbolic tangent function of quaternion $x$

Input Data

This calculator uses the same input format as used in bidual number calculation in Dual/Bidual Number Calculator except that this calculator supports only 12 functions mentioned above.

As an example, let's see how to calculate the dot product and the cross product of two three-dimentional vectors using the quaternion multiplication. Let two vector be $\vec{v_1}=(1,2,3)$ and $\vec{v_2}=(4,5,6)$. The corresponding quaternions are $x_1=0+\mathbf{i}+2\mathbf{j}+3\mathbf{k}=(0,1,2,3)$ and $x_2=0+4\mathbf{i}+5\mathbf{j}+6\mathbf{k}=(0,4,5,6)$, respectively. We want to find $x_1*x_2$, so here are the input $2\times 4$ matrix:

        0  1  2  3
        0  4  5  6
    
and the math expression
        x1*x2
    
getting the result
        -32.0000     -3.0000      6.0000     -3.0000
    
The quaternion multiplication results in the dot product \[\vec{v_1}\cdot\vec{v_2}=32=-(\text{the scalar part of the quaternion}) \] and cross product \[ \vec{v_1}\times\vec{v_2}=(-3,6,-3)=\text{the vector part of the quaternion} \]

One more example, let's use this application to calculate the same 3D rotation as in Rotation in three dimensions. We want to rotate $\frac{\pi}{2}$ radians counterclockwisely 3D point with coordinate $(6,0,0)$ around the direction vector $(0,0,1)$ which goes through the fixed point $(3,4,0)$. The corresponding quaternions for the points are $x_1=(0,6,0,0)$ and $x_2=(0,3,4,0)$, respectively. Note that the scalar parts of both quaternions are zero. The unit quaternion of the direction vector for the rotation is \[ x_3=\left( \cos\left(\frac{\pi/2}{2}\right),0,0, \sin\left(\frac{\pi/2}{2}\right) \right) =\left(\frac{1}{\sqrt{2}},0,0,\frac{1}{\sqrt{2}}\right) \] The new point after rotation is calculated from $x_2+x_3(x_1-x_2)/x_3$. So here are the input $3\times 4$ matrix:

        0  6  0  0
        0  3  4  0
        1/sqrt(2)  0  0  1/sqrt(2)
    
and the math expression
        x2+x3*(x1-x2)/x3
    
getting the result
        0.0000     7.0000     7.0000     0.0000  
    
The vector part $(7,7,0)$ is the new point, of $(6,0,0)$, after the rotation.

Quaternion Calculator