TITLE: How to solve an ODE of this form $\dot{P}(t)=A^TP(t)+P(t)A$?
QUESTION [5 upvotes]: Background
If $\dot{x}(t)=A \,x(t)$, then we know the solution is $x(t)=e^{At}x(0)$. 
Question
Now let $\dot{P}(t)=A^TP(t)+P(t)A$, what is $P(t)$?
Attempt
If we take $P(t)$ as common factor (I'm not sure I'm doing this correctly though) ,then we have: 
$$
\dot{P}(t)=A^TP(t)+P(t)A=(A^T+A)P(t)
$$ 
and using the same rationale in the background section, we have 
$$
P(t)=e^{(A^T+A) t}P(0)=e^{A^T t}P(0)e^{At}
$$
Is this a correct solution?
Note
I know the answer is $P(t)=e^{A^T t}P(0)e^{At}$ but I'm not sure how to find it.

REPLY [2 votes]: Consider the differential equation
$$
\dot{P}(t)=A^TP(t)+P(t)A
$$
We can rewrite it as:
$$
\dot{P}(\tau)-A^TP(\tau)-P(\tau)A=0
$$
Multiply the last differential equation by $e^{-A^T\tau}$ from the left and by $e^{-A\tau}$ from the right then 
\begin{equation}
e^{-A^T\tau}\dot{P}(\tau)e^{-A\tau}-e^{-A^T\tau}A^TP(\tau)e^{-A\tau}-e^{-A^T\tau}P(\tau)Ae^{-A\tau}=0 \quad (1)
\end{equation}
We can easily see that equation $(1)$ is generated by the derivative of three multiplied functions:
 \begin{equation}
\frac{d}{d\tau}\bigg(e^{-A^T\tau}{P}(\tau)e^{-A\tau}\bigg)=e^{-A^T\tau}\dot{P}(\tau)e^{-A\tau}-A^Te^{-A^T\tau}P(\tau)e^{-A\tau}-e^{-A^T\tau}P(\tau)Ae^{-A\tau}=0
\end{equation}
So we come up with:
$0=\frac{d}{d\tau}\bigg(e^{-A^T\tau}{P}(\tau)e^{-A\tau}\bigg)$
Take the integral of both sides
\begin{equation}
0=\int_0^t\frac{d}{d\tau}\bigg(e^{-A^T\tau}{P}(\tau)e^{-A\tau}\bigg)d\tau=\bigg(e^{-A^T\tau}{P}(\tau)e^{-A\tau}\bigg)\bigg]_0^t=e^{-A^Tt}{P} \tau)e^{-At}-e^{0}{P}(0)e^{0}\end{equation}
 \
\begin{equation}
0=e^{-A^Tt}{P}(t)e^{-At}-P(0)
\end{equation}
Multiply left and right sides by $e^{A^Tt}$ and $e^{At}$ respectively, we get:
\begin{equation}
P(t)=e^{A^Tt}{P}(0)e^{At}
\end{equation}
Note: I used the fact that $e^{-A^T\tau}$ and $A^T$ commute, i.e. $A^Te^{-A^T\tau}=e^{-A^T\tau}A^T$