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.
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 asH\R
– bdecaf