Mercurial > hg > ltpda
comparison m-toolbox/classes/@ssm/blockMatMult.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 % multiplies block defined matrix stored inside cell array | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: cell_mult multiplies block defined matrix stored inside cell | |
5 % array | |
6 % | |
7 % CALL: [cell3] = ssm.blockMatMult(cell1,cell2,isnotempty_1,isnotempty_2) | |
8 % | |
9 % INPUTS: | |
10 % cell1 - cell array of matrices representing a matrix by blocs. | |
11 % blocs may be empty | |
12 % cell2 - cell array of matrices representing a matrix by blocs. | |
13 % blocs may be empty | |
14 % | |
15 % OPTIONNAL INPUTS: | |
16 % isnotempty_1 - logical array tells ~isequal(cell1{ii,jj},[]) | |
17 % isnotempty_2 - logical array tells ~isequal(cell2{ii,jj},[]) | |
18 % | |
19 % OUTPUTS: | |
20 % cell3 - cell array of matrices representing a matrix by blocs. | |
21 % blocs may be empty | |
22 % | |
23 % NOTE : function is private to the ssm class | |
24 % | |
25 % VERSION: '$Id: blockMatMult.m,v 1.7 2011/04/08 08:56:24 hewitson Exp $' | |
26 % | |
27 % TO DO : | |
28 % check ME in case of mixed symbolic and double | |
29 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
30 | |
31 function c = blockMatMult(varargin) | |
32 a=varargin{1}; | |
33 b =varargin{2}; | |
34 n1 = size(a,1); | |
35 n2 = size(a,2); | |
36 n3 = size(b,2); | |
37 if nargin == 4 | |
38 sizes1 = varargin{3}; | |
39 sizes3 = varargin{4}; | |
40 if numel(sizes1)~=n1 | |
41 error('Incompatible user input (3rd argument does not correctly indicate final line heights)'); | |
42 elseif numel(sizes3)~=n3 | |
43 error('Incompatible user output (4th argument does not correctly indicate final column widths)'); | |
44 end | |
45 end | |
46 c = cell(n1,n3); | |
47 if isempty(a)||isempty(b) | |
48 % if the content matrix is empty | |
49 if n2==0 && n1>0 && n3>0 | |
50 if nargin == 4 | |
51 | |
52 c = ssm.blockMatFillDiag(c,sizes1,sizes3); | |
53 else | |
54 error('cannot build proper matrices') | |
55 end | |
56 end | |
57 else | |
58 % if matrices are not empty | |
59 isnotempty_a = not(cellfun(@isempty, a)); | |
60 isnotempty_b = not(cellfun(@isempty, b)); | |
61 % extra check for the extended diagonal | |
62 for ii=1:max(n1, n2) | |
63 isnotempty_a(min(ii,n1),min(ii,n2)) = true; | |
64 end | |
65 for ii=1:max(n2, n3) | |
66 isnotempty_b(min(ii,n2), min(ii,n3)) = true; | |
67 end | |
68 isempty_c = true(n1,n3); | |
69 for ii=1:n1 | |
70 for kk=1:n2 | |
71 if isnotempty_a(ii,kk) | |
72 for jj=1:n3 | |
73 if isnotempty_b(kk,jj) | |
74 if isempty_c(ii,jj) | |
75 % note that the matrix multiplication preserves a non-empty block diagonal | |
76 if (isempty(a{ii,kk}) || isempty(b{kk,jj})) | |
77 % exception for the case where you have one or more empty matrix | |
78 c{ii,jj} = zeros(size(a{ii,kk},1), size(b{kk,jj},2)); | |
79 else | |
80 c{ii,jj} = a{ii,kk}*b{kk,jj}; | |
81 end | |
82 isempty_c(ii,jj) = false; | |
83 else | |
84 if (isempty(a{ii,kk}) || isempty(b{kk,jj})) | |
85 % exception for the case where you have one or more empty matrix | |
86 else | |
87 c{ii,jj} = c{ii,jj} + a{ii,kk}*b{kk,jj}; | |
88 end | |
89 end | |
90 end | |
91 end | |
92 end | |
93 end | |
94 end | |
95 end | |
96 end |