Solving a Sylvester equation - Won't give me the right answer in MATLAB

351 Views Asked by At

I'm trying to solve the sylvester equation, but it won't work for me.

The Sylvester equation is:

$$AX + XB = C$$

Very simple.

And the solution $X$ (if we know $A, B, C$) can be found from this equation:

$$(I \otimes A + B^T \otimes I) vec(X) = vec(C)$$

In MATLAB or GNU Octave, $X$ can be found by this example:

>> A
A =

   1  -1   1
   1   1  -1
   1   1   1

>> B
B =

   8   1   6
   3   5   7
   4   9   2

>> C
C =

 Diagonal Matrix

   1   0   0
   0   1   0
   0   0   1

>> X = C(:)\(kron(eye(3), A) + kron(B', eye(3)))
X =

 Columns 1 through 6:

   3.00000  -0.00000   2.33333   1.33333   2.00000   2.00000

 Columns 7 through 9:

   1.66667   3.33333   1.00000

>> X = reshape(X, [3 3])
X =

   3.00000   1.33333   1.66667
  -0.00000   2.00000   3.33333
   2.33333   2.00000   1.00000

My question is: Why does matrix $X$ have those values? It will result this equation:

$$AX + XB \neq C$$

Have I compute the solution in wrong way?

Because

>> C = A*X + X*B
C =

   40.000   26.000   30.000
   20.000   41.333   24.667
   34.000   26.667   36.000
1

There are 1 best solutions below

0
On BEST ANSWER

I found the solution now.

Insted of this:

>> X = C(:)\(kron(eye(3), A) + kron(B', eye(3)))

It should be:

>> X = (kron(eye(3), A) + kron(B', eye(3)))\C(:)

Example:

>> A
A =

   1  -1   1
   1   1  -1
   1   1   1

>> B
B =

   8   1   6
   3   5   7
   4   9   2

>> C
C =

   3   4   5
   2   1   4
   5   6   7

>> X = (kron(eye(size(A)), A) + kron(B', eye(size(B))))\C(:)
X =

   0.124351
   0.165163
   0.263884
   0.572204
   0.520991
   0.816031
   0.016376
  -0.227476
  -0.028141

>> X = reshape(X, [3 3])
X =

   0.124351   0.572204   0.016376
   0.165163   0.520991  -0.227476
   0.263884   0.816031  -0.028141

>> A*X + X*B
ans =

   3.00000   4.00000   5.00000
   2.00000   1.00000   4.00000
   5.00000   6.00000   7.00000

>> C
C =

   3   4   5
   2   1   4
   5   6   7

>>