Hello, I have a little problem, I'm dealing functions made of matrix products. My question is, how can "force" ginac to convert automatically all the 1by1 matrices to scalars?. or do I have to do it manually?? Here is a simple example. void main2(){ ex m1=symbolic_matrix(1, 3, "x"); ex m2=symbolic_matrix(3, 1, "y"); cout << m1 << std::endl; cout << m2 << std::endl; ex m3 = (m1*m2).evalm(); cout << m3 << std::endl; cout << ex_to<matrix>(m3)(0,0)<< std::endl;; ex m4 = m3-ex_to<matrix>(m3)(0,0); cout << m4 << std::endl; }; the output : [[x0,x1,x2]] [[y0],[y1],[y2]] [[y1*x1+y2*x2+y0*x0]] y1*x1+y2*x2+y0*x0 -y1*x1+[[y1*x1+y2*x2+y0*x0]]-y2*x2-y0*x0 the last line "should" be zero ?-- thanks Felipe
any ideas ? Thanks. On 18/06/2010 15:06, Felipe Bordeu wrote:
Hello,
I have a little problem, I'm dealing functions made of matrix products.
My question is, how can "force" ginac to convert automatically all the 1by1 matrices to scalars?. or do I have to do it manually??
Here is a simple example.
void main2(){ ex m1=symbolic_matrix(1, 3, "x"); ex m2=symbolic_matrix(3, 1, "y");
cout << m1 << std::endl; cout << m2 << std::endl; ex m3 = (m1*m2).evalm(); cout << m3 << std::endl; cout << ex_to<matrix>(m3)(0,0)<< std::endl;; ex m4 = m3-ex_to<matrix>(m3)(0,0); cout << m4 << std::endl; }; the output :
[[x0,x1,x2]] [[y0],[y1],[y2]] [[y1*x1+y2*x2+y0*x0]] y1*x1+y2*x2+y0*x0 -y1*x1+[[y1*x1+y2*x2+y0*x0]]-y2*x2-y0*x0
the last line "should" be zero ?--
thanks
Felipe
_______________________________________________ GiNaC-list mailing list GiNaC-list@ginac.de https://www.cebix.net/mailman/listinfo/ginac-list
-- Felipe Bordeu Weldt Ingénieur de Recherche --------------------------------------------------------------------------- Tél. : 02 40 37 68 84 Fax. : 02 40 74 74 06 Felipe.Bordeu@ec-nantes.fr GEM École Centrale de Nantes, Université de Nantes, CNRS 1 rue de la Noë BP 92101 44321 Nantes Cedex 3 ---------------------------------------------------------------------------
Dear Felipe,
On Wed, 23 Jun 2010 13:19:08 +0200, Felipe Bordeu <felipe.bordeu@ec-nantes.fr> said:
FB> any ideas ? Thanks. I think you either have to do it manually or derive your own class from matrix which will do this automatically. Please note that many simplification for matrices are not done by default because they are very time-consuming. Best wishes, Vladimir -- Vladimir V. Kisil email: kisilv@maths.leeds.ac.uk -- www: http://www.maths.leeds.ac.uk/~kisilv/
This is trivial from the GiNaC tutorial: I suppose you know about evalm() Javier On Wed, 2010-06-23 at 13:19 +0200, Felipe Bordeu wrote:
any ideas ?
Thanks.
On 18/06/2010 15:06, Felipe Bordeu wrote:
Hello,
I have a little problem, I'm dealing functions made of matrix products.
My question is, how can "force" ginac to convert automatically all the 1by1 matrices to scalars?. or do I have to do it manually??
Here is a simple example.
void main2(){ ex m1=symbolic_matrix(1, 3, "x"); ex m2=symbolic_matrix(3, 1, "y");
cout << m1 << std::endl; cout << m2 << std::endl; ex m3 = (m1*m2).evalm(); cout << m3 << std::endl; cout << ex_to<matrix>(m3)(0,0)<< std::endl;; ex m4 = m3-ex_to<matrix>(m3)(0,0); cout << m4 << std::endl; }; the output :
[[x0,x1,x2]] [[y0],[y1],[y2]] [[y1*x1+y2*x2+y0*x0]] y1*x1+y2*x2+y0*x0 -y1*x1+[[y1*x1+y2*x2+y0*x0]]-y2*x2-y0*x0
the last line "should" be zero ?--
thanks
Felipe
_______________________________________________ GiNaC-list mailing list GiNaC-list@ginac.de https://www.cebix.net/mailman/listinfo/ginac-list
Skip my previous answer, I didn't read the question carefully. Javier On Wed, 2010-06-23 at 08:25 -0400, jros wrote:
This is trivial from the GiNaC tutorial: I suppose you know about evalm()
Javier
On Wed, 2010-06-23 at 13:19 +0200, Felipe Bordeu wrote:
any ideas ?
Thanks.
On 18/06/2010 15:06, Felipe Bordeu wrote:
Hello,
I have a little problem, I'm dealing functions made of matrix products.
My question is, how can "force" ginac to convert automatically all the 1by1 matrices to scalars?. or do I have to do it manually??
Here is a simple example.
void main2(){ ex m1=symbolic_matrix(1, 3, "x"); ex m2=symbolic_matrix(3, 1, "y");
cout << m1 << std::endl; cout << m2 << std::endl; ex m3 = (m1*m2).evalm(); cout << m3 << std::endl; cout << ex_to<matrix>(m3)(0,0)<< std::endl;; ex m4 = m3-ex_to<matrix>(m3)(0,0); cout << m4 << std::endl; }; the output :
[[x0,x1,x2]] [[y0],[y1],[y2]] [[y1*x1+y2*x2+y0*x0]] y1*x1+y2*x2+y0*x0 -y1*x1+[[y1*x1+y2*x2+y0*x0]]-y2*x2-y0*x0
the last line "should" be zero ?--
thanks
Felipe
_______________________________________________ GiNaC-list mailing list GiNaC-list@ginac.de https://www.cebix.net/mailman/listinfo/ginac-list
Hi! Felipe Bordeu wrote:
I have a little problem, I'm dealing functions made of matrix products.
My question is, how can "force" ginac to convert automatically all the 1by1 matrices to scalars?. or do I have to do it manually??
Here is a simple example.
void main2(){ ex m1=symbolic_matrix(1, 3, "x"); ex m2=symbolic_matrix(3, 1, "y");
cout << m1 << std::endl; cout << m2 << std::endl; ex m3 = (m1*m2).evalm(); cout << m3 << std::endl; cout << ex_to<matrix>(m3)(0,0)<< std::endl;; ex m4 = m3-ex_to<matrix>(m3)(0,0); cout << m4 << std::endl; }; the output :
[[x0,x1,x2]] [[y0],[y1],[y2]] [[y1*x1+y2*x2+y0*x0]] y1*x1+y2*x2+y0*x0 -y1*x1+[[y1*x1+y2*x2+y0*x0]]-y2*x2-y0*x0
the last line "should" be zero ?--
You'll have to do it "manually". Just write a function that replaces all 1x1 matrices with their 0,0 elements. This is of course because there is nothing special about vectors. They are just 1xn or nx1 matrices. -richy. -- Richard B. Kreckel <http://www.ginac.de/~kreckel/>
participants (4)
-
Felipe Bordeu
-
jros
-
Richard B. Kreckel
-
Vladimir V. Kisil