Solving a first order linear matrix differential equation

I am struggling in solving the following differential equation (with B and g real numbers)

        (*definition*)
H = B*{{1, 0}, {0, -1}};
L = (1/Sqrt[2])*{{1, 0}, {0, -1}};
(*initial condition*)
R[0] = {{R00, R01}, {R10, R11}};

(*solution*)
sol = DSolve[{D[R[t], t] == (-I)*(H . R[t] - R[t] . H) + g*(L . R[t] . L - R[t]),
R[0]}, R, t]


I expect the solution given by the following $$2 \times 2$$ matrix: $$R(t) = \begin{pmatrix} R_{00}(0) & R_{01}(0) e^{-i 2Bt - g t} \\ R_{10}(0) e^{i 2Bt - g t} & R_{11}(0) \end{pmatrix}$$

• You need to write the initial conditions like: ini= R[0]=={{R00, R01}, {R10, R11}} Commented May 8 at 7:57
• Thanks, @DanielHuber. Tried this sol = DSolve[{D[R[t], t] == (-I)*(H . R[t] - R[t] . H) + g*(L . R[t] . L - R[t]), ini}, R, t] but doesn't work. Commented May 8 at 8:03

Write the matrix elementwise then it will work:

H = B*{{1, 0}, {0, -1}};
L = (1/Sqrt[2])*{{1, 0}, {0, -1}};
ini = R[0] == {{R00, R01}, {R10, R11}};

R[t_] = {{r11[t], r12[t]}, {r21[t], r22[t]}};
sol = DSolve[{D[R[t], t] == (-I)*(H . R[t] - R[t] . H) +
g*(L . R[t] . L - R[t]), ini}, Flatten[R[t]], t]


R[t] /. sol // TableForm


• Thanks. Just trying to understand, why do we need Flatten[R[t]] here? Flatten seems to me "vectorizing" the matrix. Since left and right sides are $2\times 2$ matrices, why do we need to write R[t] in that vectorized form? Commented May 8 at 8:38
• DSolve wants a list of variables. Flatten transforms the matrix into a list. Commented May 8 at 10:32