Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Special matrix multiplication
Replies: 18   Last Post: Mar 22, 2012 5:12 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Milos Milenkovic

Posts: 168
Registered: 4/4/09
Re: Special matrix multiplication
Posted: Mar 22, 2012 5:12 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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




Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.