# How to integrate $e^{t \ln q} p e^{-t \ln q} dt$ for quaternion $q$ and $p$?

Trying to solve an inertial navigation problem in terms of quaternions, I ended up with the following indefinite integral $$I = \int e^{t \ln q} \, p \, e^{-t \ln q} dt,$$ where $$q \in \mathbb H$$ is a unit quaternion, $$p \in \mathbb H$$ is a pure imaginary quaternion, and both $$q$$ and $$p$$ are constant with respect to the integration variable $$t \in \mathbb R$$.

Assuming $$q \neq 1$$, I integrated by parts: $$I = \int \underbrace{\mathstrut{}e^{t \ln q} p}_u \, \underbrace{\mathstrut{}e^{-t \ln q}}_{v'} \, dt = e^{t \ln q} p e^{-t \ln q} (-\ln q)^{-1} - \int e^{t \ln q} (\ln q) \, p e^{-t\ln q} (-\ln q)^{-1} \, dt, \\ I = e^{t \ln q} p \, e^{-t \ln q} (-\ln q)^{-1} + (\ln q) \, I \, (\ln q)^{-1},$$ and got the equation $$(\ln q) \, I - I \, (\ln q) = e^{t \ln q} \, p \, e^{-t \ln q}.$$

From this question I learned that the general solution for the $$ax + xb = c$$ equation is $$x= \left( |b|^2 + 2b_0a + a^2 \right)^{-1} \left( ac +c b^* \right),$$ but it did not work for my case because of zero quaternion inversion. I also tried to expand this equation into quaternion components, but came to a system of linear equations with a singular matrix. This looks quite strange to me, since I'm pretty sure this integral should exist.

Could please someone point me to a mistake in my computations and show how to calculate this antiderivative properly? Might there be a well known solution for the problem?

Note that conjugation preserves vectors, so the integrand and hence $$\mathbf{I}$$ are pure imaginary.

For pure quaternions $$\mathbf{a}$$ and $$\mathbf{b}$$,

$$\mathbf{ab}=-\mathbf{a}\cdot\mathbf{b}+\mathbf{a}\times\mathbf{b}.$$

Thus, writing $$\ln q "=\mathbf{v}$$ we have

$$(\ln q)\mathbf{I}-\mathbf{I}(\ln q)=2\mathbf{v}\times \mathbf{I}=\exp(t\mathbf{v})\mathbf{p}\exp(-t\mathbf{v}).$$

Note that $$\mathbf{v}\times\mathbf{I}$$ deletes the $$\mathbf{v}$$-component of $$\mathbf{I}$$, so this equation fails to "see" this component. However, this actually isn't a problem: conjugating by $$\exp(t\mathbf{v})$$ fixes the $$\mathbf{v}$$-component of $$\mathbf{p}$$, call it $$\mathbf{p}_{\|}$$, within the integrand for $$\mathbf{I}$$, so we may conclude the $$\mathbf{v}$$-component for $$\mathbf{I}$$ must be $$\mathbf{I}_{\|}=t\mathbf{p}_{\|}$$.

Applying $$\mathbf{v}\times$$ to $$2\mathbf{v}\times\mathbf{I}_{\perp}=\exp(t\mathbf{v})\mathbf{p}\exp(-t\mathbf{v})$$ (with $$v=\|\mathbf{v}\|$$) yields

$$-2v^2\mathbf{I}_{\perp}=\mathbf{v}\times\big(e^{t\mathbf{v}}\mathbf{p}e^{-t\mathbf{v}}\big)$$

from which we may conclude

$$\mathbf{I}=t\big(\mathbf{p}\cdot\frac{\mathbf{v}}{\|\mathbf{v}\|}\big)\frac{\mathbf{v}}{\|\mathbf{v}\|}+\frac{1}{2}\big(e^{t\mathbf{v}}\mathbf{p}e^{-t\mathbf{v}}\big)\times\frac{\mathbf{v}}{\,\,\|\mathbf{v}\|^2}+\mathbf{C}.$$

Another route is to expand the exponentials $$\exp(t\mathbf{v})$$ using Euler's formula so you can multiply out and integrate directly. This works especially nice if, setting $$\hat{\mathbf{v}}=\frac{\mathbf{v}}{\|\mathbf{v}\|}$$ you write $$\mathbf{p}$$ with respect to an oriented orthonormal basis $$\{\mathbf{u},\hat{\mathbf{v}},\mathbf{w}\}$$.