
Special matrix multiplication problem
Posted:
Mar 15, 2012 12:54 PM


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 threevalue numbers is: > > (ai,bi,ci)*(di,ei,fi) = (bi*di+ei*(aibi), bi*ei , ei*ci+bi(fiei))
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+(A1A2)*B2; C2 = A2*B2; C3 = A3*B2+A2*(B3B2); 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*(fiei), bi*ei , ei*ci+bi(diei)) 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*(fiei), bi*ei , ei*ai+bi(diei)) 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

