Hello! :) When performing matrix multiplications expressions get expanded like in the following Example. Is there a way to avoid expansion, that is to leave the parenthesis Thanks Javier Ros Example: ----------------- matrix aux1 [[-d331*sin(q3)*dq3-d332*cos(q3)*dq3],[d331*cos(q3)*dq3-d332*sin(q3)*dq3],[0]] matrix R23 [[cos(q3),-sin(q3),0],[sin(q3),cos(q3),0],[0,0,1]] matrix R12.mul(aux1) [[d332*sin(q2)*sin(q3)*dq3-d331*cos(q2)*sin(q3)*dq3-d332*cos(q3)*cos(q2)*dq3-d331*sin(q2)*cos(q3)*dq3],[-d332*cos(q2)*sin(q3)*dq3-d331*sin(q2)*sin(q3)*dq3+d331*cos(q3)*cos(q2)*dq3-d332*sin(q2)*cos(q3)*dq3],[0]] ----------------- What I want is to obtain something like cos(q3)*(-d331*sin(q3)*dq3-d332*cos(q3)*dq3)+.... and so on for the first (0,0) matrix element.
Sorry, I fogot the subjet I found that performing programing the matrix product myself I get the desired result (Sum_k A(i,k)*B(k,i)). But is there a more elegant way? Javier Ros On Tue, 2006-03-07 at 19:31 +0100, Javier Ros Ganuza wrote:
Hello! :)
When performing matrix multiplications expressions get expanded like in the following Example.
Is there a way to avoid expansion, that is to leave the parenthesis
Thanks
Javier Ros
Example: ----------------- matrix aux1
[[-d331*sin(q3)*dq3-d332*cos(q3)*dq3],[d331*cos(q3)*dq3-d332*sin(q3)*dq3],[0]]
matrix R23
[[cos(q3),-sin(q3),0],[sin(q3),cos(q3),0],[0,0,1]]
matrix R12.mul(aux1)
[[d332*sin(q2)*sin(q3)*dq3-d331*cos(q2)*sin(q3)*dq3-d332*cos(q3)*cos(q2)*dq3-d331*sin(q2)*cos(q3)*dq3],[-d332*cos(q2)*sin(q3)*dq3-d331*sin(q2)*sin(q3)*dq3+d331*cos(q3)*cos(q2)*dq3-d332*sin(q2)*cos(q3)*dq3],[0]] -----------------
What I want is to obtain something like
cos(q3)*(-d331*sin(q3)*dq3-d332*cos(q3)*dq3)+.... and so on for the first (0,0) matrix element.
_______________________________________________ GiNaC-list mailing list GiNaC-list@ginac.de https://www.cebix.net/mailman/listinfo/ginac-list
Hello! On Tue, Mar 07, 2006 at 07:49:21PM +0100, Javier Ros Ganuza wrote:
I found that performing programing the matrix product myself I get the desired result (Sum_k A(i,k)*B(k,i)). But is there a more elegant way?
Javier Ros
On Tue, 2006-03-07 at 19:31 +0100, Javier Ros Ganuza wrote:
Hello! :)
When performing matrix multiplications expressions get expanded like in the following Example.
Is there a way to avoid expansion, that is to leave the parenthesis
You can try this silly patch: Index: ginac/matrix.cpp =================================================================== RCS file: /home/cvs/GiNaC/ginac/matrix.cpp,v retrieving revision 1.99.2.5 diff -u -r1.99.2.5 matrix.cpp --- ginac/matrix.cpp 19 Oct 2005 21:21:56 -0000 1.99.2.5 +++ ginac/matrix.cpp 8 Mar 2006 18:51:06 -0000 @@ -583,7 +583,7 @@ if (m[r1*col+c].is_zero()) continue; for (unsigned r2=0; r2<other.cols(); ++r2) - prod[r1*other.col+r2] += (m[r1*col+c] * other.m[c*other.col+r2]).expand(); + prod[r1*other.col+r2] += (m[r1*col+c] * other.m[c*other.col+r2]); } } return matrix(row, other.col, prod); Best regards, Alexei. -- All science is either physics or stamp collecting.
Sheplyakov Alexei wrote:
You can try this silly patch:
Index: ginac/matrix.cpp =================================================================== RCS file: /home/cvs/GiNaC/ginac/matrix.cpp,v retrieving revision 1.99.2.5 diff -u -r1.99.2.5 matrix.cpp --- ginac/matrix.cpp 19 Oct 2005 21:21:56 -0000 1.99.2.5 +++ ginac/matrix.cpp 8 Mar 2006 18:51:06 -0000 @@ -583,7 +583,7 @@ if (m[r1*col+c].is_zero()) continue; for (unsigned r2=0; r2<other.cols(); ++r2) - prod[r1*other.col+r2] += (m[r1*col+c] * other.m[c*other.col+r2]).expand(); + prod[r1*other.col+r2] += (m[r1*col+c] * other.m[c*other.col+r2]); } } return matrix(row, other.col, prod);
I think the expansion was unintentional and I have applied this patch to the trunk. Thanks. In matrix operations, in particularl in the elimination algorithms, one frequently needs to try a bit harder than if (foo.is_zero())... to test for zeros. One also needs to take some care to avoid excessively long terms to build up. For the elements of a matrix product, I see no need for the former, but I do see need for the latter. For instance, consider evalm([[(a+b),0],[0,(c+d)]]^666); in ginsh notation. Cheers -richy. -- Richard B. Kreckel <http://www.ginac.de/~kreckel/>
Thanks for the different replies. I've got the idea. I'm geting impressed with ginac. I'm using it to perform a rather simple task, but I was unable to deal with it with matlab(symbolic) or maple, due to their limitations in subs funtions. Incredible fine piece of work! Thank you Javier On Wed, 2006-03-08 at 23:24 +0100, Richard B. Kreckel wrote:
Sheplyakov Alexei wrote:
You can try this silly patch:
Index: ginac/matrix.cpp =================================================================== RCS file: /home/cvs/GiNaC/ginac/matrix.cpp,v retrieving revision 1.99.2.5 diff -u -r1.99.2.5 matrix.cpp --- ginac/matrix.cpp 19 Oct 2005 21:21:56 -0000 1.99.2.5 +++ ginac/matrix.cpp 8 Mar 2006 18:51:06 -0000 @@ -583,7 +583,7 @@ if (m[r1*col+c].is_zero()) continue; for (unsigned r2=0; r2<other.cols(); ++r2) - prod[r1*other.col+r2] += (m[r1*col+c] * other.m[c*other.col+r2]).expand(); + prod[r1*other.col+r2] += (m[r1*col+c] * other.m[c*other.col+r2]); } } return matrix(row, other.col, prod);
I think the expansion was unintentional and I have applied this patch to the trunk. Thanks.
In matrix operations, in particularl in the elimination algorithms, one frequently needs to try a bit harder than if (foo.is_zero())... to test for zeros. One also needs to take some care to avoid excessively long terms to build up. For the elements of a matrix product, I see no need for the former, but I do see need for the latter. For instance, consider evalm([[(a+b),0],[0,(c+d)]]^666); in ginsh notation.
Cheers -richy.
participants (3)
-
Javier Ros Ganuza
-
Richard B. Kreckel
-
varg@theor.jinr.ru