# AQB+CQD=E - how to solve for Q?

Asked by Matt Hobby on 3 Aug 2012
Latest activity Commented on by Matt Hobby on 5 Aug 2012

I am trying to find Q in the following :

` AQB+CQD=E`

All parameters are matrices (up to 12x12). Q is a 6x6 matrix with all non-diagonal values set to zero. Having a pre-multipler and a post-multiplier is causing me some problems.

I could expand it out into a series of linear equations and then do a linear regression on the results to find the diagonals of Q. However, this is tedious to complete (and therefore prone to error). I suspect there is a suitable MATLAB function that can help me. Any pointers would be very welcome.

Thanks

Matt

Miro on 3 Aug 2012

you have to be more accurate concerning your Problem. What is A,B C,D and E? What is known, what unknown?

Star Strider on 3 Aug 2012

Much depends on the structure and condition numbers of your matrices. Never having seen your equation before, the best I can do is refer you to ‘Systems of Linear Equations’ http://www.mathworks.com/help/techdoc/math/f4-983672.html

John Petersen on 3 Aug 2012

Your statement that all parameters are up to 12x12 (I'm assuming you mean A,B,C,D,E), but that Q is 6x6 conflicts with your form of the equation. It helps to know that Q is diagonal, but I reiterate what Miro asks, what are ABCDE? vectors, matrices, what?

## Products

No products are associated with this question.

Answer by Teja Muppirala on 4 Aug 2012

Just making some test data...

```A = randn(12,6);
B = randn(6,12);
C = randn(12,6);
D = randn(6,12);
Q_true = diag(randn(6,1));
E = A*Q_true*B + C*Q_true*D;
```

You can solve it using linear algebra:

```M = arrayfun(@(k) reshape((A(:,k) * B(k,:) + C(:,k) * D(k,:)),[],1),1:size(A,2),'uniform',0);
M = cat(2,M{:});
Q_solution = diag(M\E(:))
```

Or solve it by using FSOLVE:

```f = @(q) norm(A*diag(q)*B + C*diag(q)*D - E,'fro')
Q_solution = diag(fsolve(f,zeros(6,1)));
```

## 1 Comment

Matt Hobby on 5 Aug 2012

Thanks Teja!