ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 15 Apr 2013 10:14:24 -0500Matrix of vectorshttp://ask.sagemath.org/question/10008/matrix-of-vectors/Hi.
Suppose that I have a collection of vectors $v_1, \ldots, v_n \in \mathbb{R}^3$ and I wish to compute all cross products $v_i \times v_j \in \mathbb{R}^3$ where $1 \leq i < j \leq n$. Is it possible to store the output in a matrix, i.e. can I form a matrix M in Sage where $M(i,j) = v_i \times v_j$?Wed, 10 Apr 2013 01:04:16 -0500http://ask.sagemath.org/question/10008/matrix-of-vectors/Answer by DG44 for <p>Hi.</p>
<p>Suppose that I have a collection of vectors $v_1, \ldots, v_n \in \mathbb{R}^3$ and I wish to compute all cross products $v_i \times v_j \in \mathbb{R}^3$ where $1 \leq i < j \leq n$. Is it possible to store the output in a matrix, i.e. can I form a matrix M in Sage where $M(i,j) = v_i \times v_j$?</p>
http://ask.sagemath.org/question/10008/matrix-of-vectors/?answer=14767#post-id-14767What I would like is to create a matrix M where M(i,j) is a vector, not just a real number!
The code you gave produces a 2x2 matrix just of real numbers I believe. I want vectors to specify the entries M(i,j) of M, not the rows/columns.Wed, 10 Apr 2013 01:33:13 -0500http://ask.sagemath.org/question/10008/matrix-of-vectors/?answer=14767#post-id-14767Comment by slelievre for <p>What I would like is to create a matrix M where M(i,j) is a vector, not just a real number! </p>
<p>The code you gave produces a 2x2 matrix just of real numbers I believe. I want vectors to specify the entries M(i,j) of M, not the rows/columns.</p>
http://ask.sagemath.org/question/10008/matrix-of-vectors/?comment=17889#post-id-17889You should have written this as a comment to calc314's answer, not as an answer to your question.
On the other hand, ppurka's answer is appropriate and you should accept it (click the "accept" button) so that you question is displayed as solved and the correct answer is highlighted.Mon, 15 Apr 2013 10:14:24 -0500http://ask.sagemath.org/question/10008/matrix-of-vectors/?comment=17889#post-id-17889Answer by calc314 for <p>Hi.</p>
<p>Suppose that I have a collection of vectors $v_1, \ldots, v_n \in \mathbb{R}^3$ and I wish to compute all cross products $v_i \times v_j \in \mathbb{R}^3$ where $1 \leq i < j \leq n$. Is it possible to store the output in a matrix, i.e. can I form a matrix M in Sage where $M(i,j) = v_i \times v_j$?</p>
http://ask.sagemath.org/question/10008/matrix-of-vectors/?answer=14766#post-id-14766Try the following.
v1=vector([1,1])
v2=vector([2,3])
m=matrix([v1,v2])
mWed, 10 Apr 2013 01:27:34 -0500http://ask.sagemath.org/question/10008/matrix-of-vectors/?answer=14766#post-id-14766Answer by ppurka for <p>Hi.</p>
<p>Suppose that I have a collection of vectors $v_1, \ldots, v_n \in \mathbb{R}^3$ and I wish to compute all cross products $v_i \times v_j \in \mathbb{R}^3$ where $1 \leq i < j \leq n$. Is it possible to store the output in a matrix, i.e. can I form a matrix M in Sage where $M(i,j) = v_i \times v_j$?</p>
http://ask.sagemath.org/question/10008/matrix-of-vectors/?answer=14769#post-id-14769What kind of operations would you do on a 3-dimensional matrix? As far as I know this is not possible in Sage because the matrix needs to be defined over some ring. If you are not doing any fancy operations, then you might as well just store the vectors in a list of lists.
sage: v = vector(ZZ, [1,2,3])
sage: w = vector(ZZ, [2,3,4])
sage: V = [v, w]
sage: L = [[a.cross_product(b) for b in V] for a in V]
sage: L
[[(0, 0, 0), (-1, 2, -1)], [(1, -2, 1), (0, 0, 0)]]Wed, 10 Apr 2013 06:35:40 -0500http://ask.sagemath.org/question/10008/matrix-of-vectors/?answer=14769#post-id-14769