Solving a matrix exponential integral... I have $A$ and $B$ square matrices and I want to get rid of the integral in
$$
\int_0^Te^{-As}(-A+B)e^{Bs}~ds.
$$
This looks very related to the formula 
$$ \left(\int_0^T e^{At} dt \right) A + I = e^{AT} $$
that was mentioned here . But I don't get it...
 A: I found a closed form solution by means of the theory of differential equations:
If someone gets a direct proof by matrix calculations, I will be happy to accept it. Anyways, here is my solution:
Consider the (matrix-valued) linear ODE:
$$
\dot X = BX, \quad X(0)=I
$$
and its solution $X(t) = e^{Bt}$.
The same $X$ then solves
$$
\dot X = AX + (B-A)e^{Bt}, \quad X(0)=I,
$$
which gives $X(t) = e^{At} + \int_0^t e^{A(t-s)}(B-A)e^{Bs}~ds$.
Thus 
$$
X(t) = e^{Bt} = e^{At} + \int_0^t e^{A(t-s)}(B-A)e^{Bs}~ds = e^{At} + e^{At}\int_0^t e^{-As}(B-A)e^{Bs}~ds
$$
from where finds that
$$
\int_0^t e^{-As}(B-A)e^{Bs}~ds = e^{-At}(e^{Bt}-e^{At})
$$
EDIT: I have removed an identity in the last formula that only holds for commuting matrices as @loupblanc pointed out. In general it only holds that 
$$
\int_0^t e^{-As}(B-A)e^{Bs}~ds = e^{-At}(e^{Bt}-e^{At}) = e^{-At}e^{Bt}-I.
$$
A: We agree on the fact that the product of square matrices usually has no property of commutation which makes the thing difficult. 
Still you know that by definition:
$$e^{-As}=\sum_{k=0}^{\infty}A^k\frac{(-s)^k}{k!}$$
And :
$$e^{Bs}=\sum_{i=0}^{\infty}B^i\frac{s^i}{i!}$$
Thus :
$$\int_{0}^{T}e^{-As}(-A+B)e^{Bs}ds=\int_{0}^{T}\sum_{k=0}^{\infty}A^k\frac{(-s)^k}{k!}(-A+B)\sum_{i=0}^{\infty}B^i\frac{s^i}{i!}ds$$
$$=\int_{0}^{T}\sum_{k=0}^{\infty}\sum_{i=0}^{\infty}A^k(-A+B)B^i\frac{(-1)^ks^{i+k}}{k!i!}ds$$
Then you can use an interversion theorem to get the integral into the sum and to write :
$$=\sum_{k=0}^{\infty}\sum_{i=0}^{\infty}A^k(-A+B)B^i\frac{(-1)^k}{k!i!}\int_{0}^{T}s^{i+k}ds$$
You can certainly go back to an expression with exponentials from there.
$$=\sum_{k=0}^{\infty}\sum_{i=0}^{\infty}A^k(-A+B)B^i\frac{(-1)^k}{k!i!}\frac{T^{i+k+1}}{i+k+1}$$
$$=\sum_{k=0}^{\infty}\sum_{i=0}^{\infty}A^{k+1}B^i\frac{(-1)^{k+1}}{k!i!}\frac{T^{i+k+1}}{i+k+1}+\sum_{k=0}^{\infty}\sum_{i=0}^{\infty}A^kB^{i+1}\frac{(-1)^k}{k!i!}\frac{T^{i+k+1}}{i+k+1}$$
$$=\sum_{k=0}^{\infty}\sum_{i=0}^{\infty}\frac{(-TA)^{k+1}}{k!}\frac{(TB)^i}{i!}\frac{1}{i+k+1}+\sum_{k=0}^{\infty}\sum_{i=0}^{\infty}\frac{(-TA)^{k}}{k!}\frac{(TB)^{i+1}}{i!}\frac{1}{i+k+1}$$
