Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Special matrix multiplication

Subject: Special matrix multiplication

From: Milos Milenkovic

Date: 4 Feb, 2012 11:59:23

Message: 1 of 19

Dear,
suppose that we have two matrices, where each element has three values like follows:

A=[(a1,b1,c1), (a2,b2,c2); (a3,b3,c3), (a4,b4,c4)]
B=[(d1,e1,f1), (d2,e2,f2); (d3,e3,f3), (d4,e4,f4)]

Now, I have to multiply these two matrices, and that is matrix C=A*B

C=[ c11=(a1,b1,c1)*(d1,e1,f1)+(a2,b2,c2)*(d3,e3,f3), c12=(a1,b1,c1)*(d2,e2,f2)+(a2,b2,c2)*(d4,e4,f4); c21=(a3,b3,c3)*(d1,e1,f1)+(a4,b4,c4)*(d3,e3,f3), c22=(a3,b3,c3)*(d2,e2,f2)+(a4,b4,c4)*(d4,e4,f4)]

where the most important here is the low for multiplying these three-value numbers is:

(ai,bi,ci)*(di,ei,fi) = (bi*di+ei*(ai-bi), bi*ei , ei*ci+bi(fi-ei))

Please, how to do this, I have a dozen of this matrices with 700x700 in dimension approximately.
Best,
Milos

Subject: Special matrix multiplication

From: John D'Errico

Date: 4 Feb, 2012 12:27:18

Message: 2 of 19

"Milos Milenkovic" <m.milenkovic@mathworks.com> wrote in message <jgj6ir$rj7$1@newscl01ah.mathworks.com>...
> Dear,
> suppose that we have two matrices, where each element has three values like follows:
>
> A=[(a1,b1,c1), (a2,b2,c2); (a3,b3,c3), (a4,b4,c4)]
> B=[(d1,e1,f1), (d2,e2,f2); (d3,e3,f3), (d4,e4,f4)]
>
> Now, I have to multiply these two matrices, and that is matrix C=A*B
>
> C=[ c11=(a1,b1,c1)*(d1,e1,f1)+(a2,b2,c2)*(d3,e3,f3), c12=(a1,b1,c1)*(d2,e2,f2)+(a2,b2,c2)*(d4,e4,f4); c21=(a3,b3,c3)*(d1,e1,f1)+(a4,b4,c4)*(d3,e3,f3), c22=(a3,b3,c3)*(d2,e2,f2)+(a4,b4,c4)*(d4,e4,f4)]
>
> where the most important here is the low for multiplying these three-value numbers is:
>
> (ai,bi,ci)*(di,ei,fi) = (bi*di+ei*(ai-bi), bi*ei , ei*ci+bi(fi-ei))
>
> Please, how to do this, I have a dozen of this matrices with 700x700 in dimension approximately.
> Best,
> Milos

While there is no magic that will let you do this for
no effort on your part, I still don't see the problem.

You can just write a function that takes a pair of triads,
and "multiplies" them by your rule.

Then just write another function that takes a pair of
matrices, and multiplies them, again as per your rule.

Its just a few loops. Whats the problem? You can even
build a special class for the purpose, where you define
a "multiply" to be anything you wish between class
members.

Its not even a big problem, but even if it was, you
eat even an elephantine computational problem one
byte at a time. Just start writing.

John

Subject: Special matrix multiplication

From: Milos Milenkovic

Date: 4 Feb, 2012 14:40:33

Message: 3 of 19

"John D'Errico" <woodchips@rochester.rr.com> wrote in message <jgj876$2rh$1@newscl01ah.mathworks.com>...
> "Milos Milenkovic" <m.milenkovic@mathworks.com> wrote in message <jgj6ir$rj7$1@newscl01ah.mathworks.com>...
> > Dear,
> > suppose that we have two matrices, where each element has three values like follows:
> >
> > A=[(a1,b1,c1), (a2,b2,c2); (a3,b3,c3), (a4,b4,c4)]
> > B=[(d1,e1,f1), (d2,e2,f2); (d3,e3,f3), (d4,e4,f4)]
> >
> > Now, I have to multiply these two matrices, and that is matrix C=A*B
> >
> > C=[ c11=(a1,b1,c1)*(d1,e1,f1)+(a2,b2,c2)*(d3,e3,f3), c12=(a1,b1,c1)*(d2,e2,f2)+(a2,b2,c2)*(d4,e4,f4); c21=(a3,b3,c3)*(d1,e1,f1)+(a4,b4,c4)*(d3,e3,f3), c22=(a3,b3,c3)*(d2,e2,f2)+(a4,b4,c4)*(d4,e4,f4)]
> >
> > where the most important here is the low for multiplying these three-value numbers is:
> >
> > (ai,bi,ci)*(di,ei,fi) = (bi*di+ei*(ai-bi), bi*ei , ei*ci+bi(fi-ei))
> >
> > Please, how to do this, I have a dozen of this matrices with 700x700 in dimension approximately.
> > Best,
> > Milos
>
> While there is no magic that will let you do this for
> no effort on your part, I still don't see the problem.
>
> You can just write a function that takes a pair of triads,
> and "multiplies" them by your rule.
>
> Then just write another function that takes a pair of
> matrices, and multiplies them, again as per your rule.
>
> Its just a few loops. Whats the problem? You can even
> build a special class for the purpose, where you define
> a "multiply" to be anything you wish between class
> members.
>
> Its not even a big problem, but even if it was, you
> eat even an elephantine computational problem one
> byte at a time. Just start writing.
>
> John

Dear John,
please be a little more explicit, I know all of that, but I do not have a time to start from zero.
I suppose that I can use some standard matrix multiplication function written in Matlab and make certain changes.
Best,
Milos

Subject: Special matrix multiplication

From: Roger Stafford

Date: 4 Feb, 2012 20:37:40

Message: 4 of 19

"Milos Milenkovic" <m.milenkovic@mathworks.com> wrote in message <jgjg11$o4c$1@newscl01ah.mathworks.com>...
> ......... I do not have a time to start from zero.
> I suppose that I can use some standard matrix multiplication function written in Matlab and make certain changes.
- - - - - - - - - -
  Your "multiplication" rule bears a vague resemblance to the kronecker tensor product which matlab computes using the 'kron' function. Unfortunately it is only a resemblance and I don't see how you could actually use 'kron' for what you are doing.

  I tend to agree with John that you would have to write your own special multiplication function "from the ground up" for this purpose. I see no matlab functions that would help you very much except of course for the basic multiplication, addition, and subtraction of scalars.

  It is the special rule for multiplication of two three-element vectors for which you have written

 (ai,bi,ci)*(di,ei,fi) = (bi*di+ei*(ai-bi), bi*ei , ei*ci+bi(fi-ei))

that makes it difficult to apply other standard functions. This latter has a clean logic to it which makes it a fascinating notion but it is decidedly different from anything I know of in matlab.

  Again I agree with John. I don't think it would be very hard to write such a routine. It all looks very straightforward but would certainly require some nested for-loops and probably be a function which calls on at least one other function which you also write.

  Out of curiosity, do you have in mind a generalization on what you have defined with A and B? Your A and B are of 2 by 6 size. I think I can see how it would generalize to a multiplication of n by 3*n arrays. Such a routine would not be appreciably more difficult to write than for just 2 by 6 arrays. Your mention of 700 by 700 arrays has made me think of this possibility. However 700 is not a multiple of 3 so I wonder what you really meant by your remark. Did you mean 700 by 3*700? I assume that you realize that ordinary matlab arrays (as opposed to cell arrays) cannot possess elements which are themselves arrays.

Roger Stafford

Subject: Special matrix multiplication

From: Roger Stafford

Date: 5 Feb, 2012 02:30:38

Message: 5 of 19

"Milos Milenkovic" <m.milenkovic@mathworks.com> wrote in message <jgj6ir$rj7$1@newscl01ah.mathworks.com>...
> suppose that we have two matrices, where each element has three values like follows:
>
> A=[(a1,b1,c1), (a2,b2,c2); (a3,b3,c3), (a4,b4,c4)]
> B=[(d1,e1,f1), (d2,e2,f2); (d3,e3,f3), (d4,e4,f4)]
>
> Now, I have to multiply these two matrices, and that is matrix C=A*B
>
> C=[ c11=(a1,b1,c1)*(d1,e1,f1)+(a2,b2,c2)*(d3,e3,f3), c12=(a1,b1,c1)*(d2,e2,f2)+(a2,b2,c2)*(d4,e4,f4); c21=(a3,b3,c3)*(d1,e1,f1)+(a4,b4,c4)*(d3,e3,f3), c22=(a3,b3,c3)*(d2,e2,f2)+(a4,b4,c4)*(d4,e4,f4)]
>
> where the most important here is the low for multiplying these three-value numbers is:
>
> (ai,bi,ci)*(di,ei,fi) = (bi*di+ei*(ai-bi), bi*ei , ei*ci+bi(fi-ei))
- - - - - - - - -
  Hello Milos, I was wrong about not being able to use matlab functions or operators in your problem. It turns out to be very easy to do using ordinary matrix multiplication as follows. Let A and B be n by 3*n matrices. Then do this to "multiply" them in the sense that you have in mind.

 A1 = A(:,1:3:n); A2 = A(:,2:3:n); A3 = A(:,3:3:n);
 B1 = B(:,1:3:n); B2 = B(:,2:3:n); B3 = B(:,3:3:n);
 C1 = A2*B1+(A1-A2)*B2; C2 = A2*B2; C3 = A3*B2+A2*(B3-B2);
 C(:,3:3:end) = C3; C(:,2:3:end) = C2; C(:,1:3:end) = C1;

Then C is your "product". No for-loops needed.

  It is possible you had a different way of arranging your matrices in mind than the above n by 3*n kind. In any case something like this method should be able to be adapted to other arrangements.

Roger Stafford

Subject: Special matrix multiplication

From: ImageAnalyst

Date: 4 Feb, 2012 15:22:34

Message: 6 of 19

I don't understand your notation. What's with the parentheses? Is A a
6 column by 2 row 2D matrix? Or is A a 3D matrix where the upper left
element (row 1, column1) actually a triplet of numbers (a1,b1,c1),
kind of like an RGB image, so that A is a 2 by 2 by 3 array (2 rows by
2 columns by 3 slices/planes/colorchannels)???? Maybe you can give an
example with actual numbers.

Subject: Special matrix multiplication

From: ImageAnalyst

Date: 5 Feb, 2012 02:58:58

Message: 7 of 19

On Feb 4, 9:30 pm, "Roger Stafford"
<ellieandrogerxy...@mindspring.com.invalid> wrote:
[snip]
>   It is possible you had a different way of arranging your matrices in mind than the above n by 3*n kind.  In any case something like this method should be able to be adapted to other arrangements.
>
> Roger Stafford
-------------------------------------------
The more I read his ambiguous post, the more I started to think he had
2 by 2 by 3 matrices because he said "each element has three values"
so I'm thinking that each of the elements in a 2 by 2 matrix had 3
values along the third dimension, kind of like an RGB image. But who
knows, since Milos seems to have lost interest in his post or
forgotten about it.

Subject: Special matrix multiplication

From: Milos Milenkovic

Date: 7 Feb, 2012 17:11:10

Message: 8 of 19

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <79fc2a0e-f25d-42be-b1d4-2d3f8ba963d6@b23g2000yqn.googlegroups.com>...
> On Feb 4, 9:30 pm, "Roger Stafford"
> <ellieandrogerxy...@mindspring.com.invalid> wrote:
> [snip]
> >   It is possible you had a different way of arranging your matrices in mind than the above n by 3*n kind.  In any case something like this method should be able to be adapted to other arrangements.
> >
> > Roger Stafford
> -------------------------------------------
> The more I read his ambiguous post, the more I started to think he had
> 2 by 2 by 3 matrices because he said "each element has three values"
> so I'm thinking that each of the elements in a 2 by 2 matrix had 3
> values along the third dimension, kind of like an RGB image. But who
> knows, since Milos seems to have lost interest in his post or
> forgotten about it.

Dear Roger and ImageAnalyst,
I gave up and decided to make a function for this multiplication, but thanks to Roger the problem is solved. In a better and faster way. Yes, these are fuzzy matrices and each value is presented as three values (approximately two is 1,5;2;2,5)
Once again dear Roger thanks!!!!

Subject: Special matrix multiplication

From: Steven_Lord

Date: 7 Feb, 2012 18:04:47

Message: 9 of 19



"Milos Milenkovic" <m.milenkovic@mathworks.com> wrote in message
news:jgrlve$roe$1@newscl01ah.mathworks.com...
> ImageAnalyst <imageanalyst@mailinator.com> wrote in message
> <79fc2a0e-f25d-42be-b1d4-2d3f8ba963d6@b23g2000yqn.googlegroups.com>...
>> On Feb 4, 9:30 pm, "Roger Stafford"
>> <ellieandrogerxy...@mindspring.com.invalid> wrote:
>> [snip]
>> > It is possible you had a different way of arranging your matrices in
>> > mind than the above n by 3*n kind. In any case something like this
>> > method should be able to be adapted to other arrangements.
>> >
>> > Roger Stafford
>> -------------------------------------------
>> The more I read his ambiguous post, the more I started to think he had
>> 2 by 2 by 3 matrices because he said "each element has three values"
>> so I'm thinking that each of the elements in a 2 by 2 matrix had 3
>> values along the third dimension, kind of like an RGB image. But who
>> knows, since Milos seems to have lost interest in his post or
>> forgotten about it.
>
> Dear Roger and ImageAnalyst,
> I gave up and decided to make a function for this multiplication, but
> thanks to Roger the problem is solved. In a better and faster way. Yes,
> these are fuzzy matrices and each value is presented as three values
> (approximately two is 1,5;2;2,5)
> Once again dear Roger thanks!!!!

Are you trying to perform interval arithmetic? If so, doing a Google search
for that term along with MATLAB showed several toolboxes for doing exactly
that; one that I've heard of (but not personally used) is INTLAB.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Special matrix multiplication

From: Milos Milenkovic

Date: 7 Feb, 2012 19:58:11

Message: 10 of 19

Dear Steven,
I use INTLAB for fuzzy matrix inverse computation (these matrices are transformed to interval for the purpose of inverse computation). But for multiplication, addition I use the original three point - fuzzy estimate.
Best

"Steven_Lord" <slord@mathworks.com> wrote in message <jgrp3v$8lm$1@newscl01ah.mathworks.com>...
>
>
> "Milos Milenkovic" <m.milenkovic@mathworks.com> wrote in message
> news:jgrlve$roe$1@newscl01ah.mathworks.com...
> > ImageAnalyst <imageanalyst@mailinator.com> wrote in message
> > <79fc2a0e-f25d-42be-b1d4-2d3f8ba963d6@b23g2000yqn.googlegroups.com>...
> >> On Feb 4, 9:30 pm, "Roger Stafford"
> >> <ellieandrogerxy...@mindspring.com.invalid> wrote:
> >> [snip]
> >> > It is possible you had a different way of arranging your matrices in
> >> > mind than the above n by 3*n kind. In any case something like this
> >> > method should be able to be adapted to other arrangements.
> >> >
> >> > Roger Stafford
> >> -------------------------------------------
> >> The more I read his ambiguous post, the more I started to think he had
> >> 2 by 2 by 3 matrices because he said "each element has three values"
> >> so I'm thinking that each of the elements in a 2 by 2 matrix had 3
> >> values along the third dimension, kind of like an RGB image. But who
> >> knows, since Milos seems to have lost interest in his post or
> >> forgotten about it.
> >
> > Dear Roger and ImageAnalyst,
> > I gave up and decided to make a function for this multiplication, but
> > thanks to Roger the problem is solved. In a better and faster way. Yes,
> > these are fuzzy matrices and each value is presented as three values
> > (approximately two is 1,5;2;2,5)
> > Once again dear Roger thanks!!!!
>
> Are you trying to perform interval arithmetic? If so, doing a Google search
> for that term along with MATLAB showed several toolboxes for doing exactly
> that; one that I've heard of (but not personally used) is INTLAB.
>
> --
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com

Subject: Special matrix multiplication

From: Roger Stafford

Date: 7 Feb, 2012 21:37:09

Message: 11 of 19

"Milos Milenkovic" <m.milenkovic@mathworks.com> wrote in message <jgrvoj$34u$1@newscl01ah.mathworks.com>...
> I use INTLAB for fuzzy matrix inverse computation (these matrices are transformed to interval for the purpose of inverse computation). But for multiplication, addition I use the original three point - fuzzy estimate.
- - - - - - - -
  I am curious as to what format you plan to use to store your fuzzy matrices as matlab entities. The n by 3*n form I used for you was just a guess.

  In case it is of interest to you, your multiplication operation satisfies both the associative and distributive laws, as I imagine you expected.

Roger Stafford

Subject: Special matrix multiplication

From: Milos Milenkovic

Date: 15 Mar, 2012 16:10:29

Message: 12 of 19

Dear all,
Recently I had a problem like this
suppose that we have two matrices, where each element has three values like follows:
>
> A=[(a1,b1,c1), (a2,b2,c2); (a3,b3,c3), (a4,b4,c4)]
> B=[(d1,e1,f1), (d2,e2,f2); (d3,e3,f3), (d4,e4,f4)]
>
> Now, I have to multiply these two matrices, and that is matrix C=A*B
>
> C=[ c11=(a1,b1,c1)*(d1,e1,f1)+(a2,b2,c2)*(d3,e3,f3), c12=(a1,b1,c1)*(d2,e2,f2)+(a2,b2,c2)*(d4,e4,f4); c21=(a3,b3,c3)*(d1,e1,f1)+(a4,b4,c4)*(d3,e3,f3), c22=(a3,b3,c3)*(d2,e2,f2)+(a4,b4,c4)*(d4,e4,f4)]
>
> where the most important here is the low for multiplying these three-value numbers is:
>
> (ai,bi,ci)*(di,ei,fi) = (bi*di+ei*(ai-bi), bi*ei , ei*ci+bi(fi-ei))

and we (Roger S.) solved it as follows:
 A1 = A(:,1:3:n); A2 = A(:,2:3:n); A3 = A(:,3:3:n);
 B1 = B(:,1:3:n); B2 = B(:,2:3:n); B3 = B(:,3:3:n);
 C1 = A2*B1+(A1-A2)*B2; C2 = A2*B2; C3 = A3*B2+A2*(B3-B2);
 C(:,3:3:end) = C3; C(:,2:3:end) = C2; C(:,1:3:end) = C1;

This is ok, but now I have to make this multiplication with respect to sign of these (ai,bi,ci) numbers, so if (ai,bi,ci) and (di,ei,fi) are >0 (they are >0, if bi and ei >0) then the upper solution is ok,
but when bi or ei is <0 than I have to apply next rule:
(ai,bi,ci)*(di,ei,fi) = (ei*ai+bi*(fi-ei), bi*ei , ei*ci+bi(di-ei))
Or, if (ai,bi,ci) and (di,ei,fi) are both <0 (they are <0, if bi and ei <0)
(ai,bi,ci)*(di,ei,fi) = (ei*ci+bi*(fi-ei), bi*ei , ei*ai+bi(di-ei))
So now, first I have to check if bi and ei are > or < and then to apply an appropriate rule for multiplying.
Any idea how to solve this?
Example:
A=[2 3 4 5 6 7; -3 -2 -1 3 4 5]
B=[0 2 4 -4 -3 -2; -6 -4 -3 4 7 8]
C=A*B
C=[c11=(2 3 4)*(0 2 4)+(5 6 7)*(-6 -4 -3) c12=(2 3 4)*(-4 -3 -2)+(5 6 7)*(4 7 8); c21=(-3 -2 -1)*(-4 -3 -2)+(3 4 5)*(4 7 8) c22=….]
Best,
Milos

Subject: Special matrix multiplication

From: Roger Stafford

Date: 15 Mar, 2012 19:21:34

Message: 13 of 19

"Milos Milenkovic" <m.milenkovic@mathworks.com> wrote in message <jjt49l$nak$1@newscl01ah.mathworks.com>...
> .......
> This is ok, but now I have to make this multiplication with respect to sign of these (ai,bi,ci) numbers, so if (ai,bi,ci) and (di,ei,fi) are >0 (they are >0, if bi and ei >0) then the upper solution is ok,
> but when bi or ei is <0 than I have to apply next rule:
> (ai,bi,ci)*(di,ei,fi) = (ei*ai+bi*(fi-ei), bi*ei , ei*ci+bi(di-ei))
> Or, if (ai,bi,ci) and (di,ei,fi) are both <0 (they are <0, if bi and ei <0)
> (ai,bi,ci)*(di,ei,fi) = (ei*ci+bi*(fi-ei), bi*ei , ei*ai+bi(di-ei))
> .......
- - - - - - - - - - -
  Hello again Milos. The rules I gave you earlier can easily be revised to the following for the two new cases:

 A1 = A(:,1:3:n); A2 = A(:,2:3:n); A3 = A(:,3:3:n);
 B1 = B(:,1:3:n); B2 = B(:,2:3:n); B3 = B(:,3:3:n);
 C1 = A1*B2+A2*(B3-B2); C2 = A2*B2; C3 = A3*B2+A2*(B1-B2);
 C(:,3:3:end) = C3; C(:,2:3:end) = C2; C(:,1:3:end) = C1;

and

 A1 = A(:,1:3:n); A2 = A(:,2:3:n); A3 = A(:,3:3:n);
 B1 = B(:,1:3:n); B2 = B(:,2:3:n); B3 = B(:,3:3:n);
 C1 = A3*B2+A2*(B3-B2); C2 = A2*B2; C3 = A1*B2+A2*(B1-B2);
 C(:,3:3:end) = C3; C(:,2:3:end) = C2; C(:,1:3:end) = C1;

  However, neither of these two new definitions are associative. In other words, if P, Q, and R are matrices of this kind, it is no longer true that P*(Q*R) is identically equal to (P*Q)*R where '*' represents either of your new multiplication rules. Your original special multiplication was in fact associative as I mentioned earlier. This makes me suspicious of your two new kinds of multiplication operators. Any "multiplication" which is not even associative is in my opinion a very ugly kind of multiplication and hardly worthy of the name. What in the world are you using it for?

Roger Stafford

Subject: Special matrix multiplication

From: Milos Milenkovic

Date: 15 Mar, 2012 20:47:18

Message: 14 of 19

Dear Roger,
thanks again, I already tried to modify your first code on just the same way as you proposed, but the result is not correct, I will try tomorrow and then ask for help. Do you have some good propossal for if statement, how to check the positiveness of bi and ei?
This is the procedure for fuzzy numbers multiplying, so I used it in multiplying matrices composed from fuzzy numbers.

Thanks once again!
Best,
Milos

"Roger Stafford" wrote in message <jjtffu$3hn$1@newscl01ah.mathworks.com>...
> "Milos Milenkovic" <m.milenkovic@mathworks.com> wrote in message <jjt49l$nak$1@newscl01ah.mathworks.com>...
> > .......
> > This is ok, but now I have to make this multiplication with respect to sign of these (ai,bi,ci) numbers, so if (ai,bi,ci) and (di,ei,fi) are >0 (they are >0, if bi and ei >0) then the upper solution is ok,
> > but when bi or ei is <0 than I have to apply next rule:
> > (ai,bi,ci)*(di,ei,fi) = (ei*ai+bi*(fi-ei), bi*ei , ei*ci+bi(di-ei))
> > Or, if (ai,bi,ci) and (di,ei,fi) are both <0 (they are <0, if bi and ei <0)
> > (ai,bi,ci)*(di,ei,fi) = (ei*ci+bi*(fi-ei), bi*ei , ei*ai+bi(di-ei))
> > .......
> - - - - - - - - - - -
> Hello again Milos. The rules I gave you earlier can easily be revised to the following for the two new cases:
>
> A1 = A(:,1:3:n); A2 = A(:,2:3:n); A3 = A(:,3:3:n);
> B1 = B(:,1:3:n); B2 = B(:,2:3:n); B3 = B(:,3:3:n);
> C1 = A1*B2+A2*(B3-B2); C2 = A2*B2; C3 = A3*B2+A2*(B1-B2);
> C(:,3:3:end) = C3; C(:,2:3:end) = C2; C(:,1:3:end) = C1;
>
> and
>
> A1 = A(:,1:3:n); A2 = A(:,2:3:n); A3 = A(:,3:3:n);
> B1 = B(:,1:3:n); B2 = B(:,2:3:n); B3 = B(:,3:3:n);
> C1 = A3*B2+A2*(B3-B2); C2 = A2*B2; C3 = A1*B2+A2*(B1-B2);
> C(:,3:3:end) = C3; C(:,2:3:end) = C2; C(:,1:3:end) = C1;
>
> However, neither of these two new definitions are associative. In other words, if P, Q, and R are matrices of this kind, it is no longer true that P*(Q*R) is identically equal to (P*Q)*R where '*' represents either of your new multiplication rules. Your original special multiplication was in fact associative as I mentioned earlier. This makes me suspicious of your two new kinds of multiplication operators. Any "multiplication" which is not even associative is in my opinion a very ugly kind of multiplication and hardly worthy of the name. What in the world are you using it for?
>
> Roger Stafford

Subject: Special matrix multiplication

From: Roger Stafford

Date: 16 Mar, 2012 01:15:35

Message: 15 of 19

"Milos Milenkovic" <m.milenkovic@mathworks.com> wrote in message <jjtkgm$k9n$1@newscl01ah.mathworks.com>...
> Dear Roger,
> thanks again, I already tried to modify your first code on just the same way as you proposed, but the result is not correct, I will try tomorrow and then ask for help. Do you have some good propossal for if statement, how to check the positiveness of bi and ei?
> This is the procedure for fuzzy numbers multiplying, so I used it in multiplying matrices composed from fuzzy numbers.
> ........
- - - - - - - - - -
A1 = A(:,1:3:n); A2 = A(:,2:3:n); A3 = A(:,3:3:n);
B1 = B(:,1:3:n); B2 = B(:,2:3:n); B3 = B(:,3:3:n);
A2P = (A2>0); B2P = (B2>0);
S1 = (A2P&B2P); S2 = (A2P~=B2P); S3 = ~(A2P|B2P);
C1 = S1.*(A2*B1+(A1-A2)*B2)+S2.*(A1*B2+A2*(B3-B2))+S3.*(A3*B2+A2*(B3-B2));
C2 = A2*B2;
C3 = S1.*(A3*B2+A2*(B3-B2))+S2.*(A3*B2+A2*(B1-B2))+S3.*(A1*B2+A2*(B1-B2));
C(:,3:3:end) = C3; C(:,2:3:end) = C2; C(:,1:3:end) = C1;

  This could be slow. You might prefer to write it all out with for-loops.

Roger Stafford

Subject: Special matrix multiplication

From: Roger Stafford

Date: 16 Mar, 2012 19:26:17

Message: 16 of 19

"Roger Stafford" wrote in message <jju47n$74f$1@newscl01ah.mathworks.com>...
> "Milos Milenkovic" <m.milenkovic@mathworks.com> wrote in message <jjtkgm$k9n$1@newscl01ah.mathworks.com>...
> > Dear Roger,
> > thanks again, I already tried to modify your first code on just the same way as you proposed, but the result is not correct, I will try tomorrow and then ask for help. Do you have some good propossal for if statement, how to check the positiveness of bi and ei?
> > This is the procedure for fuzzy numbers multiplying, so I used it in multiplying matrices composed from fuzzy numbers.
> > ........
> - - - - - - - - - -
> A1 = A(:,1:3:n); A2 = A(:,2:3:n); A3 = A(:,3:3:n);
> B1 = B(:,1:3:n); B2 = B(:,2:3:n); B3 = B(:,3:3:n);
> A2P = (A2>0); B2P = (B2>0);
> S1 = (A2P&B2P); S2 = (A2P~=B2P); S3 = ~(A2P|B2P);
> C1 = S1.*(A2*B1+(A1-A2)*B2)+S2.*(A1*B2+A2*(B3-B2))+S3.*(A3*B2+A2*(B3-B2));
> C2 = A2*B2;
> C3 = S1.*(A3*B2+A2*(B3-B2))+S2.*(A3*B2+A2*(B1-B2))+S3.*(A1*B2+A2*(B1-B2));
> C(:,3:3:end) = C3; C(:,2:3:end) = C2; C(:,1:3:end) = C1;
- - - - - - - -
  You should ignore that last solution I sent you, Milos. It occurred to me late last night that it can't possibly work. I believe it is inherent in "fuzzy" computation, as you have modified it to be dependent on the signs of those middle terms, that only the middle term can be carried out by the regular matrix multiplication operation. The other two terms need to be done using for-loops, nested three deep. There seems no getting around that.

  The following is such a routine, but you cannot expect it to be anywhere near as fast as regular matrix multiplication. It is assumed here that A and B are of size n by 3*n. If you wish to generalize it to an m-by-3*n times n-by-3*p size multiplication, it should be easy to modify it accordingly.

n = size(A,1);
A1 = A(:,1:3:3*n); A2 = A(:,2:3:3*n); A3 = A(:,3:3:3*n);
B1 = B(:,1:3:3*n); B2 = B(:,2:3:3*n); B3 = B(:,3:3:3*n);
C1 = zeros(n); C3 = zeros(n);
for i1 = 1:n
 for i2 = 1:n
  if A2(i1,i2) > 0
   for i3 = 1:n
    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:n
    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;
C = zeros(n,3*n);
C(:,1:3:3*n) = C1; C(:,2:3:3*n) = C2; C(:,3:3:3*n) = C3;

The result is in C.

Roger Stafford

Subject: Special matrix multiplication

From: Milos Milenkovic

Date: 19 Mar, 2012 15:25:11

Message: 17 of 19

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.

function [C]=prodrs(A,B)
[a,b]=size(A);
[c,d]=size(B);
a = size(A,1);%broj vrsta matrice
A1 = A(:,1:3:end); A2 = A(:,2:3:end); A3 = A(:,3:3:end);
B1 = B(:,1:3:end); B2 = B(:,2:3:end); B3 = B(:,3:3:end);
C1 = zeros(a,3*c); C3 = zeros(c,3*d);
for i1 = 1:a
 for i2 = 1:a
  if A2(i1,i2) > 0
   for i3 = 1:3*c
    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)*A3(i1,i2)+A2(i1,i2)*(B1(i2,i3)-B2(i2,i3));
     C3(i1,i3) = C3(i1,i3)+B2(i2,i3)*A1(i1,i2)+A2(i1,i2)*(B3(i2,i3)-B2(i2,i3));
    end
   end
  else
   for i3 = 1:3*c
    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;
C = zeros(a,d);
C(:,1:3:end) = C1; C(:,2:3:end) = C2; C(:,3:3:end) = C3;

Best,
Milos




"Roger Stafford" wrote in message <jk044p$sm0$1@newscl01ah.mathworks.com>...
> "Roger Stafford" wrote in message <jju47n$74f$1@newscl01ah.mathworks.com>...
> > "Milos Milenkovic" <m.milenkovic@mathworks.com> wrote in message <jjtkgm$k9n$1@newscl01ah.mathworks.com>...
> > > Dear Roger,
> > > thanks again, I already tried to modify your first code on just the same way as you proposed, but the result is not correct, I will try tomorrow and then ask for help. Do you have some good propossal for if statement, how to check the positiveness of bi and ei?
> > > This is the procedure for fuzzy numbers multiplying, so I used it in multiplying matrices composed from fuzzy numbers.
> > > ........
> > - - - - - - - - - -
> > A1 = A(:,1:3:n); A2 = A(:,2:3:n); A3 = A(:,3:3:n);
> > B1 = B(:,1:3:n); B2 = B(:,2:3:n); B3 = B(:,3:3:n);
> > A2P = (A2>0); B2P = (B2>0);
> > S1 = (A2P&B2P); S2 = (A2P~=B2P); S3 = ~(A2P|B2P);
> > C1 = S1.*(A2*B1+(A1-A2)*B2)+S2.*(A1*B2+A2*(B3-B2))+S3.*(A3*B2+A2*(B3-B2));
> > C2 = A2*B2;
> > C3 = S1.*(A3*B2+A2*(B3-B2))+S2.*(A3*B2+A2*(B1-B2))+S3.*(A1*B2+A2*(B1-B2));
> > C(:,3:3:end) = C3; C(:,2:3:end) = C2; C(:,1:3:end) = C1;
> - - - - - - - -
> You should ignore that last solution I sent you, Milos. It occurred to me late last night that it can't possibly work. I believe it is inherent in "fuzzy" computation, as you have modified it to be dependent on the signs of those middle terms, that only the middle term can be carried out by the regular matrix multiplication operation. The other two terms need to be done using for-loops, nested three deep. There seems no getting around that.
>
> The following is such a routine, but you cannot expect it to be anywhere near as fast as regular matrix multiplication. It is assumed here that A and B are of size n by 3*n. If you wish to generalize it to an m-by-3*n times n-by-3*p size multiplication, it should be easy to modify it accordingly.
>
> n = size(A,1);
> A1 = A(:,1:3:3*n); A2 = A(:,2:3:3*n); A3 = A(:,3:3:3*n);
> B1 = B(:,1:3:3*n); B2 = B(:,2:3:3*n); B3 = B(:,3:3:3*n);
> C1 = zeros(n); C3 = zeros(n);
> for i1 = 1:n
> for i2 = 1:n
> if A2(i1,i2) > 0
> for i3 = 1:n
> 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:n
> 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;
> C = zeros(n,3*n);
> C(:,1:3:3*n) = C1; C(:,2:3:3*n) = C2; C(:,3:3:3*n) = C3;
>
> The result is in C.
>
> Roger Stafford

Subject: Special matrix multiplication

From: Roger Stafford

Date: 19 Mar, 2012 18:34:11

Message: 18 of 19

"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

Subject: Special matrix multiplication

From: Milos Milenkovic

Date: 22 Mar, 2012 09:12:18

Message: 19 of 19

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

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us