Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Solve Matrix Equation AX=XB, Clarification

Subject: Solve Matrix Equation AX=XB, Clarification

From: Jeremy

Date: 17 Jul, 2013 18:01:29

Message: 1 of 10

I'm doing a school project with a vector network analyzer and gathering data on four adapters which I'll call a,b,c,d. Each of these devices can be characterized with a 2x2 matrix, and when you multiply these matrices together you get a 2x2 matrix that characterizes these adapters hooked together. I am hooking the adapters up in the configurations a-c-b and a-d-b which gives the resultant 2x2 matrices that I'll call s and t. I know the characteristic matrices for c and d but not a and b, and it is my goal to solve for them. So the resulting equations look like the following:
[s] = [a][c][b]
[t] = [a][d][b]
The left size is data and the right side is unknowns AND data. They are all 2x2 matrices.

Multiplying the first equation by the inverse of the second cancels [b] and I get the following equation:
([s]/[t])[a] = [a]([c]/[d])
Since I'm solving for [a] this equation is equivalent to the special sylvester equation:
[A][X]=[X][B]
Which has been discussed previously in this thread:
http://www.mathworks.com/matlabcentral/newsreader/view_thread/253765
They give the following matlab code:
%
n = length(A);
G = kron(eye(n),A)-kron(B.',eye(n));
x = null(G)
%

To see if the equations given in this thread would work for me I created dummy values for [a],[b],[c], and [d], used them to solve for [s] and [t], and used them with the equations given to see if they would give me back [a]. The matlab code is the following:

%initial values
a =[2, 3;5, 7];
b =[11 , 13;17 , 19];
c =[23 , 29;31 , 37];
d =[41 , 43;47 , 53];
%setup
s = av*c*b;
t = a*d*b;
A = s/t;
B = c/d;
%calculate
n = length(A);
G = kron(eye(n),A)-kron(B.',eye(n));
x = null(G)
%

I do not however get the expected result for [a]! Is it a problem of not having an initial value or something like that? I have a few more measurements I could make to introduce an initial value but from there I'm not sure how to combine these equations.
Thanks!

Subject: Solve Matrix Equation AX=XB, Clarification

From: Steven_Lord

Date: 17 Jul, 2013 21:50:19

Message: 2 of 10



"Jeremy " <jlawrence6809@gmail.com> wrote in message
news:ks6m5p$8di$1@newscl01ah.mathworks.com...
> I'm doing a school project with a vector network analyzer and gathering
> data on four adapters which I'll call a,b,c,d. Each of these devices can
> be characterized with a 2x2 matrix, and when you multiply these matrices
> together you get a 2x2 matrix that characterizes these adapters hooked
> together. I am hooking the adapters up in the configurations a-c-b and
> a-d-b which gives the resultant 2x2 matrices that I'll call s and t. I
> know the characteristic matrices for c and d but not a and b, and it is my
> goal to solve for them. So the resulting equations look like the
> following:

*snip*

> To see if the equations given in this thread would work for me I created
> dummy values for [a],[b],[c], and [d], used them to solve for [s] and [t],
> and used them with the equations given to see if they would give me back
> [a]. The matlab code is the following:
>
> %initial values
> a =[2, 3;5, 7];
> b =[11 , 13;17 , 19];
> c =[23 , 29;31 , 37];
> d =[41 , 43;47 , 53];
> %setup
> s = av*c*b;

I assume this was supposed to be a*c*b?

> t = a*d*b;
> A = s/t;
> B = c/d;

For A*X = X*B, one solution is the appropriately sized zero matrix. This is
the solution the LYAP function in Control System Toolbox returns.

http://www.mathworks.com/help/control/ref/lyap.html

> %calculate
> n = length(A);
> G = kron(eye(n),A)-kron(B.',eye(n));
> x = null(G)

NULL gives _A_ basis for the nullspace of G. You can check that it gives you
a solution of your system of equations:

xv = reshape(x(:, 1), [2 2]);
A*xv-xv*B

The difference seems pretty small to me, smaller even than A*a-a*B.

> I do not however get the expected result for [a]! Is it a problem of not
> having an initial value or something like that? I have a few more
> measurements I could make to introduce an initial value but from there I'm
> not sure how to combine these equations.

You're assuming uniqueness. Since you wrote your equation in the form
A*X=X*B, your B is the negative of the B using the form in the Wikipedia
entry:

http://en.wikipedia.org/wiki/Sylvester_equation

So your equation has a unique solution if and only if your A and B have no
common eigenvalues. It looks to me like they have two (out of two)
eigenvalues that are pretty darn close to being the same.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Solve Matrix Equation AX=XB, Clarification

From: Jeremy

Date: 18 Jul, 2013 00:00:15

Message: 3 of 10

"Steven_Lord" <slord@mathworks.com> wrote in message <ks73is$e9o$1@newscl01ah.mathworks.com>...
*snip
> So your equation has a unique solution if and only if your A and B have no
> common eigenvalues. It looks to me like they have two (out of two)
> eigenvalues that are pretty darn close to being the same.

Hmm thats too bad. I took a bunch of data and the eigenvalues for the resultant A and B matrices were also very close, resulting in empty matrices for x.

I took one more row of data [u] using another device e giving me another equation as follows:
([s]/[u])[a] = [a]([c]/[e])

I also used another test setup to get new scalar data n and m. These relate to [a] according to the (not obvious) following equation:
0 = (a(1,2) + ((a(1,1)*a(2,2)-a(1,2)*a(2,1))*m)/(a(2,2)+a(2,1)*m))/a(2,2) - n

 I used the equations above as well as the previous equation in fsolve to see if that could come up with anything, and though it gave me results, they were definitely not accurate. a(1,1) and a(2,2) were much more accurate for whatever reason. Should I just keep adding data (f, g, h, etc...) until fsolve can find the correct answer? Is there a way to combine multiple data sets in the for AX=XB to get a better result?

Subject: Solve Matrix Equation AX=XB, Clarification

From: dpb

Date: 18 Jul, 2013 00:49:28

Message: 4 of 10

On 7/17/2013 7:00 PM, Jeremy wrote:
> "Steven_Lord" <slord@mathworks.com> wrote in message
> <ks73is$e9o$1@newscl01ah.mathworks.com>...
> *snip
>> So your equation has a unique solution if and only if your A and B
>> have no common eigenvalues. It looks to me like they have two (out of
>> two) eigenvalues that are pretty darn close to being the same.
>
> Hmm thats too bad. I took a bunch of data and the eigenvalues for the
> resultant A and B matrices were also very close, resulting in empty
> matrices for x.
> I took one more row of data [u] using another device e giving me another
> equation as follows:
> ([s]/[u])[a] = [a]([c]/[e])
>
> I also used another test setup to get new scalar data n and m. These
> relate to [a] according to the (not obvious) following equation:
> 0 = (a(1,2) +
> ((a(1,1)*a(2,2)-a(1,2)*a(2,1))*m)/(a(2,2)+a(2,1)*m))/a(2,2) - n
>
> I used the equations above as well as the previous equation in fsolve to
> see if that could come up with anything, and though it gave me results,
> they were definitely not accurate. a(1,1) and a(2,2) were much more
> accurate for whatever reason. Should I just keep adding data (f, g, h,
> etc...) until fsolve can find the correct answer? Is there a way to
> combine multiple data sets in the for AX=XB to get a better result?

What you need to do is to back up and figure out a set of test
conditions of the independent variables that are, a priori, _NOT_ going
to be linearly dependent. That's called "experiment design" in
statistical terms.

I've no clue what you're measuring, but simply randomly throwing data at
it is not the way to get somewhere.

--

Subject: Solve Matrix Equation AX=XB, Clarification

From: Jeremy

Date: 18 Jul, 2013 01:13:12

Message: 5 of 10

dpb <none@non.net> wrote in message <ks7e22$rd1$1@speranza.aioe.org>...
> On 7/17/2013 7:00 PM, Jeremy wrote:
> > "Steven_Lord" <slord@mathworks.com> wrote in message
> > <ks73is$e9o$1@newscl01ah.mathworks.com>...
>
> What you need to do is to back up and figure out a set of test
> conditions of the independent variables that are, a priori, _NOT_ going
> to be linearly dependent. That's called "experiment design" in
> statistical terms.
>
> I've no clue what you're measuring, but simply randomly throwing data at
> it is not the way to get somewhere.

Hah yes you're absolutely right. Unfortunately I'm very new to this subject and not sure where to go for help/resources.

What I am measuring is a set of parameters ("s parameters") that characterize electrical "two port" devices. I these devices have two ends like a cable, and have different types of connectors (2.5mm, 3.5mm, N, etc) with different sexes so I can only connect devices in certain ways. Also the ultimate combination of hooking the devices up so I can measure them has to result in both sides of the setup to have the same connector type (different sex is fine). When devices are connected together the combined s-parameters is the individual s-parameter matrices multiplied.

If the above made no sense what it comes down to is I can take measurements that result in 2x2 complex matrices and I know these matrices are the products of multiple 2x2 complex matrices, some of which I know, others I don't. The equations look like the following:
[total 1] = [device 1][device 2][device 3]...

This necessarily results in nonlinear systems I believe... I am reading about nonlinear systems but it is a very vast and complex subject so if anyone with more knowledge could point me in the right direction it would be much appreciated. Thanks!

Subject: Solve Matrix Equation AX=XB, Clarification

From: Jeremy

Date: 18 Jul, 2013 16:50:13

Message: 6 of 10

I found something that seems to be quite useful in this thread:
http://www.mathworks.com/matlabcentral/newsreader/view_thread/82452

Here is the relevant post:
>In the presence of errors in A and B, roundoff errors in computation,
>and multiple eigenvalues, the problem gets harder. You might try
>
> [V,D] = eig(A)
> [W,E] = eig(B)
>
>Find a permutation vector p so that
>
> diag(D) = diag(E(p,p)).
>
>Replace W by W(:,p). Compute
>
> X = V/W
>
>Check to see if A*X is close enough to X*B for your purposes.


He seems to imply that having A and B with similar eigenvalues can be remedied with his method but I'm not sure how to implement it. For my example I would need to flip rows and columns of E for diag(D)=diag(E). Since E is a 2x2 matrix to flip its rows and columns is done by the following: [0 1;1 0]*E*[0 1;1 0]. What would this be in vector form?

Subject: Solve Matrix Equation AX=XB, Clarification

From: Jeremy

Date: 18 Jul, 2013 18:32:11

Message: 7 of 10

According to a resource I found online (https://hec.unil.ch/docs/files/23/100/handout1.pdf):
vecABC = (C'? A)vecB

So if I manipulated my initial equation AX = XB as following:
AXB' = X
vec(AXB') = vec(X)
(B? A)vec(X) = vec(X)
(B? A)vec(X) -vec(X) = 0
(B? A - I)vec(X) = 0
 
It becomes a linear system! Is my math correct?
Also is it useful in my case with experimentally determined [A] and [B] which have error terms?

Subject: Solve Matrix Equation AX=XB, Clarification

From: Bruno Luong

Date: 19 Jul, 2013 04:47:07

Message: 8 of 10

"Jeremy" wrote in message <ks9cbb$53n$1@newscl01ah.mathworks.com>...
> According to a resource I found online (https://hec.unil.ch/docs/files/23/100/handout1.pdf):
> vecABC = (C'? A)vecB
>
> So if I manipulated my initial equation AX = XB as following:
> AXB' = X
> vec(AXB') = vec(X)
> (B? A)vec(X) = vec(X)
> (B? A)vec(X) -vec(X) = 0
> (B? A - I)vec(X) = 0
>
> It becomes a linear system! Is my math correct?

You math is incorrect. The correct one leads to Kroneker's product that has been given in the thread in the link of your firs post.

If you can't relate the solution to your data, then you don't understand your data or you formulate wrongly the problem.

Bruno

Subject: Solve Matrix Equation AX=XB, Clarification

From: Jeremy

Date: 19 Jul, 2013 15:48:10

Message: 9 of 10

My problem was with the null function used. If you use [U,S,V] = svd(G) instead and take the last column of V as your answer then it works. I believe it has to do with small errors in my measurements.

Subject: Solve Matrix Equation AX=XB, Clarification

From: Bruno Luong

Date: 19 Jul, 2013 18:10:14

Message: 10 of 10

"Jeremy" wrote in message <ksbn3q$rtd$1@newscl01ah.mathworks.com>...
> My problem was with the null function used. If you use [U,S,V] = svd(G) instead and take the last column of V as your answer then it works. I believe it has to do with small errors in my measurements.

If don't have a too old Matlab version, NULL calls SVD (just type "edit null" if you want to check what it does). The only thing one can manually tune when calling directly SVD is the threshold used to decide the rank of the kernel.

Bruno

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us