Solve system of equations using matrices

88 Views Asked by At

Matrix of Unknowns: $X$

Known values (constants): $A, K, F$

How to solve using any programming language: $$ AX + XA^\top + K\cdot X = F $$ (${}\cdot{}$ is element wise product )

2

There are 2 best solutions below

2
On

I would try taking the elements of $X$ and vectorizing them: $$v_{\{ij\}}:=X_{ij}.$$

Same goes for $F$: $$w_{\{ij\}}:=F_{ij}.$$

In this paramaterization, the equation you want to solve is simply a linear transformation of the vector $v$ into the vector $f$:

$$L(v)=w.$$

In fact, this is just get a new matrix equation on the vector $v$:

$$Mv=w$$

where you know all elements of $M$(they come from $A$ and $K$).

Now, use basically any programming language (e.g., MATLAB) to solve this new matrix equation.

0
On

We need

The key formula is

$\text{vec}(ABC) = (C^T \otimes A) \text{vec}(B)$.

Also we have $\text{vec}(A \circ B) = D_\text{vec(A)} \text{vec}(B)$.

where $D_{\text{vec}(A)}$ denotes the diagonal matrix formed from the vector vec(A).

This gives an elegant solution of your (and related) problems:

$A X + X A^T + K \circ X = F$

gives

$(I \otimes A^T) \text{vec}(X) + (A \otimes I) \text{vec}(X) + D_{\text{vec}(K)} \text{vec}(X) = \text{vec}(F)$.

Which is easily solved for the elements of $X$ (represented by $\text{vec}(X)$)

$\text{vec}(X) = (I \otimes A^T + A \otimes I + D_\text{vec(K)})^{-1} \text{vec}(F)$.

This also tells you that a unique solution exists, if and only if $I \otimes A^T + A \otimes I + D_\text{vec(K)}$ is invertible. In the wikipedia references, you may find interesting properties of the vectorization operator and the Kronecker product, which may or may not be helpful for you. For example, the eigenvalues and eigenvectors of it are very easily obtained.