Path: news.mathworks.com!not-for-mail
From: "Milos Milenkovic" <m.milenkovic@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Special matrix multiplication
Date: Thu, 22 Mar 2012 09:12:18 +0000 (UTC)
Organization: Faculty of Transport &#38; Traffic Engineering
Lines: 49
Message-ID: <jkeqdi$mna$1@newscl01ah.mathworks.com>
References: <jgj6ir$rj7$1@newscl01ah.mathworks.com> <jgkpke$kf6$1@newscl01ah.mathworks.com> <79fc2a0e-f25d-42be-b1d4-2d3f8ba963d6@b23g2000yqn.googlegroups.com> <jgrlve$roe$1@newscl01ah.mathworks.com> <jgrp3v$8lm$1@newscl01ah.mathworks.com> <jgrvoj$34u$1@newscl01ah.mathworks.com> <jgs5i5$nfp$1@newscl01ah.mathworks.com> <jjt49l$nak$1@newscl01ah.mathworks.com> <jjtffu$3hn$1@newscl01ah.mathworks.com> <jjtkgm$k9n$1@newscl01ah.mathworks.com> <jju47n$74f$1@newscl01ah.mathworks.com> <jk044p$sm0$1@newscl01ah.mathworks.com> <jk7j4n$7as$1@newscl01ah.mathworks.com> <jk7u73$icn$1@newscl01ah.mathworks.com>
Reply-To: "Milos Milenkovic" <m.milenkovic@mathworks.com>
NNTP-Posting-Host: www-01-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1332407538 23274 172.30.248.46 (22 Mar 2012 09:12:18 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 22 Mar 2012 09:12:18 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1282758
Xref: news.mathworks.com comp.soft-sys.matlab:761810

Dear Roger, 
the code works excellent. Thanks!!!!!
Best,
Milos
"Roger Stafford" wrote in message <jk7u73$icn$1@newscl01ah.mathworks.com>...
> "Milos Milenkovic" <m.milenkovic@mathworks.com> wrote in message <jk7j4n$7as$1@newscl01ah.mathworks.com>...
> > Dear Roger,
> > this is great, thanks!!!! Just please little help with transforming the code in universal form. Dimensions are frequently the form you said, (4x3*4)*(4*3*14), I tried but somewhere I mistake.
> > ........
> - - - - - - - - - -
>   If your temporary matrices are of the sizes:
> 
>  A1, A2, A3 --> p by q
>  B1, B2, B3 --> q by r
>  C1, C2, C3 --> p by r
> 
> then the following code remains almost the same with only the appropriate replacement of n by p, q, and r in the for-loop counters:
> 
> C1 = zeros(p,r); C3 = zeros(p,r);
> for i1 = 1:p
>  for i2 = 1:q
>   if A2(i1,i2) > 0
>    for i3 = 1:r
>     if B2(i2,i3) > 0
>      C1(i1,i3) = C1(i1,i3)+A2(i1,i2)*B1(i2,i3)+B2(i2,i3)*(A1(i1,i2)-A2(i1,i2));
>      C3(i1,i3) = C3(i1,i3)+B2(i2,i3)*A3(i1,i2)+A2(i1,i2)*(B3(i2,i3)-B2(i2,i3));
>     else
>      C1(i1,i3) = C1(i1,i3)+B2(i2,i3)*A1(i1,i2)+A2(i1,i2)*(B3(i2,i3)-B2(i2,i3));
>      C3(i1,i3) = C3(i1,i3)+B2(i2,i3)*A3(i1,i2)+A2(i1,i2)*(B1(i2,i3)-B2(i2,i3));
>     end
>    end
>   else
>    for i3 = 1:r
>     if B2(i2,i3) > 0
>      C1(i1,i3) = C1(i1,i3)+B2(i2,i3)*A1(i1,i2)+A2(i1,i2)*(B3(i2,i3)-B2(i2,i3));
>      C3(i1,i3) = C3(i1,i3)+B2(i2,i3)*A3(i1,i2)+A2(i1,i2)*(B1(i2,i3)-B2(i2,i3));
>     else
>      C1(i1,i3) = C1(i1,i3)+B2(i2,i3)*A3(i1,i2)+A2(i1,i2)*(B3(i2,i3)-B2(i2,i3));
>      C3(i1,i3) = C3(i1,i3)+B2(i2,i3)*A1(i1,i2)+A2(i1,i2)*(B1(i2,i3)-B2(i2,i3));
>     end
>    end
>   end
>  end
> end
> C2 = A2*B2;
> 
>   How you extract A1, A2, A3, B1, B2, B3 from A and B, and how you insert C1, C2, and C3 back into C depends on the particular format you wish to use in these matrices.  Define carefully the format and I'll show you the extraction and insertion code if I can.  I can think of a number of different formats you might conceivably use, one of them using three-dimensional arrays.
> 
> Roger Stafford