ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 23 Dec 2014 12:15:17 -0600Sum of two vectorshttps://ask.sagemath.org/question/25331/sum-of-two-vectors/ Hi everybody, i've got this functions and variables:
v = function('v',t)
a_V_ra = function('a_V_ra',t)
a_a_ra=function('a_a_ra',t)
g = var('g')
r_V_ra = vector([v,0,0])
a_V_ra = R_ra*r_V_ra.column()
where R is a matrix and a_V_ra is the vector [cos(psi(t))v(t), sin(psi(t))v(t),0].
But when i do this:
a_a_ra = diff(a_V_ra)+vector([0,0,-g])
it says: *TypeError: unsupported operand parent(s) for '+': 'Full MatrixSpace of 3 by 1 dense matrices over Symbolic Ring' and 'Vector space of dimension 3 over Symbolic Ring'*
I guess it's saying that i'm summing a matrix and a vector, but they're both vectors! What can I do to make it work?
Thank you.
Tue, 23 Dec 2014 03:42:05 -0600https://ask.sagemath.org/question/25331/sum-of-two-vectors/Answer by calc314 for <p>Hi everybody, i've got this functions and variables:</p>
<pre><code>v = function('v',t)
a_V_ra = function('a_V_ra',t)
a_a_ra=function('a_a_ra',t)
g = var('g')
r_V_ra = vector([v,0,0])
a_V_ra = R_ra*r_V_ra.column()
</code></pre>
<p>where R is a matrix and a_V_ra is the vector [cos(psi(t))v(t), sin(psi(t))v(t),0].</p>
<p>But when i do this:</p>
<pre><code>a_a_ra = diff(a_V_ra)+vector([0,0,-g])
</code></pre>
<p>it says: <em>TypeError: unsupported operand parent(s) for '+': 'Full MatrixSpace of 3 by 1 dense matrices over Symbolic Ring' and 'Vector space of dimension 3 over Symbolic Ring'</em></p>
<p>I guess it's saying that i'm summing a matrix and a vector, but they're both vectors! What can I do to make it work?</p>
<p>Thank you.</p>
https://ask.sagemath.org/question/25331/sum-of-two-vectors/?answer=25340#post-id-25340The problem is that `diff(a_V_ra,t)` is giving you a column vector and `vector([0,0,-g])` is giving you a row vector. Further, Sage sees the first as a matrix and the second as a vector. You can fix this using `.column()` as you did earlier in your code.
a_a_ra = diff(a_V_ra,t)+vector([0,0,-g]).column()
gives:
[ cos(psi)*D[0](v)(t)]
[-sin(psi)*D[0](v)(t)]
[ -g]
My full code is:
var('psi t g')
v = function('v',t)
R_ra=matrix([[cos(psi),sin(psi),0],[-sin(psi),cos(psi),0],[0,0,1]])
r_V_ra = vector([v,0,0])
a_V_ra = R_ra*r_V_ra.column()
a_a_ra = diff(a_V_ra,t)+vector([0,0,-g]).column()
Tue, 23 Dec 2014 12:15:17 -0600https://ask.sagemath.org/question/25331/sum-of-two-vectors/?answer=25340#post-id-25340Answer by FrédéricC for <p>Hi everybody, i've got this functions and variables:</p>
<pre><code>v = function('v',t)
a_V_ra = function('a_V_ra',t)
a_a_ra=function('a_a_ra',t)
g = var('g')
r_V_ra = vector([v,0,0])
a_V_ra = R_ra*r_V_ra.column()
</code></pre>
<p>where R is a matrix and a_V_ra is the vector [cos(psi(t))v(t), sin(psi(t))v(t),0].</p>
<p>But when i do this:</p>
<pre><code>a_a_ra = diff(a_V_ra)+vector([0,0,-g])
</code></pre>
<p>it says: <em>TypeError: unsupported operand parent(s) for '+': 'Full MatrixSpace of 3 by 1 dense matrices over Symbolic Ring' and 'Vector space of dimension 3 over Symbolic Ring'</em></p>
<p>I guess it's saying that i'm summing a matrix and a vector, but they're both vectors! What can I do to make it work?</p>
<p>Thank you.</p>
https://ask.sagemath.org/question/25331/sum-of-two-vectors/?answer=25335#post-id-25335Maybe you can try something like that:
sage: m=matrix([[1],[0],[0]])
sage: v=vector([0,5,6])
sage: m.column(0)+v
(1, 5, 6)
Tue, 23 Dec 2014 08:17:08 -0600https://ask.sagemath.org/question/25331/sum-of-two-vectors/?answer=25335#post-id-25335