4
votes

The problem is as follows:
I have a set of 20 equations:

r1 = s1*h1_1 + s2*h1_2 + ... s20*h1_20

r2 = s1*h2_1 + ...

...

r20 = s1*h20_1 + ...

where r, s and h are matrices and * symbolizes pointwise product. It can be rewritten in the matrix form R = H*S. I want to solve this equation for S - so I need to calculate inv(H)*R. But how can I calculate inv(H) if each element of H is a matrix? I cannot simply concatenate these smaller matrices into a bigger matrix H and then invert it - since this will give a different result than, e.g. inverting matrix H with symbolic values and then substituting these symbolic values with smaller matrices (because of the pointwise product present in the set of equations).

Up to now I came up with 1 solution. I will create the matrix H with 20x20 symbolic values, I will invert it, and then I will evaluate each cell of the resulting inverted matrix with 'subs'.

H = sym('A',[20 20]);
invmat = inv(H) ;
% here I load 400 smaller matrices with appropriate names
invmat_11 = subs(invmat(1,1));

But inversion of such a matrix is to complicated to be calculated on any medium class computer so I never managed to run this code. Do you know any other way of calculating an inversion of matrix H - or directly solving for S?

I was asked for some simple example: Consider equation R = H*S (S is unknown). Let's say H=[A B; C D], where A,B,C,D are 2x2 matrices, e.g. A = [A11 A12; A21 A22]

and R and S are 2x1 matrices, e.g.

R = [R1;R2]

To calculate for S I need to solve inv(H)*R, symbolically inv(H) =

[ -D/(B*C - A*D), B/(B*C - A*D)] [ C/(B*C - A*D), -A/(B*C - A*D)]

Now I can substitute A,B,C and D with real 2x2 matrices and calculate the inversion of H:

inv(H) = [H1 H2; H3 H4] where

H1 = -D/(B*C - A*D)

This constitutes calculation of inv(H). Now I need to multiply inv(H) with R (to solve for S):

S1 = H1*R1 + H2*R2 S2 = H3*R1 + H4*R2

but please note, that all H1 to H4 and R1 to R2 are matrices, and * symbolizes pointwise product.

1
Could you add your (slow) solution to the question. Maybe the performance can be increased biased on that solution. How large are your smaller matrices?Daniel
Just a note - it is not efficient to calculate inv(H)*R (and even fails if H is rank deficit). The usual solution is to solve the equation - eg. use mldivide - which is short written as H\Rbdecaf
@Daniel, my slow solution is already in the question: my computer never managed to compute H = sym('A',[20 20]); invmat = inv(H); I even tried to apply the blockwise inversion ( en.wikipedia.org/wiki/Invertible_matrix#Blockwise_inversion ) so that I would need to calculate only 10x10 matrix inversion - but that is still to memory-consuming.pewter_cauldron
Could you add a simple example (say 2x2 matrices) with expected output?bdecaf
@bdecaf I added some example.pewter_cauldron

1 Answers

1
votes

I found the best solution to solve this set of equations. Actually, it is embarrassingly easy: one just has to notice that these equations can be rewritten in the form:

first_element_of_r1 = first_element_ofs1*first_element_of_h1_1 + ...

and this is due to presence of piecewise product in the equations. Now each element of r1 to r20 matrices can be solved independently in a loop (or parallel loop). Thanks everyone for trying to help me.