Is there a closed form solution the matrix differential equation
$\dot X = AX + XA^T - K $
for example when $A = \begin{bmatrix} 0 & 1 \\ 0 & 0 \end{bmatrix}$ and $K = \begin{bmatrix} 0 & 0 \\ 0 & 1 \end{bmatrix}$
In general $A$ is square and $K$ is positive semi-definite.
As far as I understand the equation:
$\dot X = AX + XA^T$
has the closed form solution
$X(t) = e^{At}Ce^{tA^T}$
Can this be extended to $\dot X = AX + XA^T - K $?
These are similar questions, but do not answer the closed form solution question:
This is a linear non-homogeneous differential equation, so the standard techniques apply. The catch is that since it is not presented in the usual form $\dot x = Ax + b$, we would either have to put this equation into that form or do things in a coordinate-free fashion.
We can reframe this problem in the standard presentation using the vectorization operator. In particular: if we define $x = \operatorname{vec}(X), k = \operatorname{vec}(K) \in \Bbb R^{4 \times 1}$ and vectorize both sides of the differential equation, then your differential equation becomes $$ \dot x = (I \otimes A + A \otimes I)x - k \implies\\ \dot x = \pmatrix{0&1&1&0\\0&0&0&1\\0&0&0&1\\0&0&0&0} x - \pmatrix{0\\0\\0\\1} $$
This differential equation has a closed form solution and can be solved using standard methods. To get the answer to the original equation, it suffices to "unvectorize" our general solution $x(t)$ to the above differential equation.
Flawed earlier attempt:
We can rewrite your differential equation as $$ \dot X -AX - XA^T = -K $$ This is a linear differential equation since the map $X \mapsto \dot X - AX - XA^T$ is linear. Your solution $X_h(t) = Ce^{At}e^{tA^T}$ solves the homogeneous problem, $\dot X - AX - XA^T = 0$. It now suffices to find a particular solution to the equation $$ \dot X -AX - XA^T = -K $$
Taking $X = t^2P + tQ + R$ as our Ansatz, we find that $$ \dot X - AX - XA^T = -K \implies\\ 2tP + Q - A(t^2P + tQ + R) - (t^2P + tQ + R)A^T = -K \implies\\ -t^2[AP + PA^T] + t[2P - AQ - QA^T] + [Q + K - AR - RA^T] $$ In other words, it suffices to find matrices $P,Q,R$ satisfying the system of equations $$ \begin{cases} AP + PA^T = 0\\ AQ + QA^T = 2P\\ AR + RA^T = Q + K \end{cases}. $$ For such $P,Q,R$, we can write our general solution as $X(t) = Ce^{At}e^{tA^T} + t^2P + tQ + R$.