Do we have a solution for the following matrix ODE: $$\frac{d\mathbf{P}}{dt} = \mathbf{A}\mathbf{P} + \mathbf{B}$$ where all matrices are square.
My guess is: $$ \mathbf{P}(t) = \exp{(\mathbf{A}t)}\mathbf{P}(0) + \mathbf{A}^{-1}[\exp{(\mathbf{A}t)}\mathbf{B} - \mathbf{B}] $$ when $\mathbf{A}$ is invertible. I am not sure it is correct and not clear when $\mathbf{A}$ is not full rank.
Assuming $A$ is constant (i.e. independent of $t$), you can use $\exp(-At)$ as an integrating factor; left-multiplying by it gives $\frac{d}{dt} \bigl( e^{-At} P(t) \bigr) = e^{-At} B(t)$, so that $$ e^{-At} P(t) - P(0) = \int_0^t e^{-As} B(s) \, ds , $$ and hence $$ P(t) = e^{At} P(0) + \int_0^t e^{A(t-s)} B(s) \, ds , $$ which holds in general, and reduces to your formula if $A$ is invertible and $B$ is constant.