ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 29 Jan 2021 14:26:30 +0100Matrix multiplication with a vector in EuclideanSpacehttps://ask.sagemath.org/question/55490/matrix-multiplication-with-a-vector-in-euclideanspace/ Hello
Oversimplified version of my question is "How can I multiply a vector with a matrix?"
E.<x,y,z>=EuclideanSpace(start_index=0)
vf=E.vector_field([x*y,x^2,z**2]) # the components are for testing purposes
M=Matrix(RR,3,3);M[:]=1 # this is just a test
# Neither this
M*vf
# nor this works
M*vf.at(E((3,2,1)))
The only work around I could think of is
v=vf.at(E((3,2,1)))
q=vector([v[0],v[1],v[2]])
M*q
or directly on the vector field
v=vector([v[0].expr(), v[1].expr(), v[2].expr()])
M*q
With this approach I have to put the transformed components back in the vector field defined within EuclideanSpace.
I would like to use EuclideanSpace to work with vectors.
Is there an easy way to handle this? Basically I am looking for an easy way to transform a vector field defined in EuclideanSpace?
Thanks in advance for your help.
Fri, 29 Jan 2021 01:25:10 +0100https://ask.sagemath.org/question/55490/matrix-multiplication-with-a-vector-in-euclideanspace/Answer by eric_g for <p>Hello</p>
<p>Oversimplified version of my question is "How can I multiply a vector with a matrix?"</p>
<pre><code>E.<x,y,z>=EuclideanSpace(start_index=0)
vf=E.vector_field([x*y,x^2,z**2]) # the components are for testing purposes
M=Matrix(RR,3,3);M[:]=1 # this is just a test
# Neither this
M*vf
# nor this works
M*vf.at(E((3,2,1)))
</code></pre>
<p>The only work around I could think of is</p>
<pre><code>v=vf.at(E((3,2,1)))
q=vector([v[0],v[1],v[2]])
M*q
</code></pre>
<p>or directly on the vector field</p>
<pre><code>v=vector([v[0].expr(), v[1].expr(), v[2].expr()])
M*q
</code></pre>
<p>With this approach I have to put the transformed components back in the vector field defined within EuclideanSpace. </p>
<p>I would like to use EuclideanSpace to work with vectors.</p>
<p>Is there an easy way to handle this? Basically I am looking for an easy way to transform a vector field defined in EuclideanSpace?</p>
<p>Thanks in advance for your help.</p>
https://ask.sagemath.org/question/55490/matrix-multiplication-with-a-vector-in-euclideanspace/?answer=55493#post-id-55493You have to convert the matrix `M` to an endomorphism of the Euclidean space and apply the latter to the vector field. Given the canonical identification between endomorphisms and tensors of type (1,1), the conversion is performed as follows:
A = E.tensor_field(1, 1, M)
Here is the full example:
sage: E.<x,y,z> = EuclideanSpace(start_index=0)
sage: vf = E.vector_field([x*y, x^2, z**2])
sage: M = Matrix(RR, 3, 3); M[:] = 1
sage: A = E.tensor_field(1, 1, M)
sage: A
Tensor field of type (1,1) on the Euclidean space E^3
sage: A[:]
[1 1 1]
[1 1 1]
[1 1 1]
sage: A(vf)
Vector field on the Euclidean space E^3
sage: A(vf).display()
(x^2 + x*y + z^2) e_x + (x^2 + x*y + z^2) e_y + (x^2 + x*y + z^2) e_z
sage: A(vf)[:]
[x^2 + x*y + z^2, x^2 + x*y + z^2, x^2 + x*y + z^2]
Note that the action of the endomorphism `A` onto the vector field `vf` is obtained by `A(vf)` and not by `A*vf`, which would perform a tensor product and would yield a tensor field of type (2, 1).
Note also that if the matrix `M` is invertible, you may perform the conversion simply as
A = E.automorphism_field(M)
Fri, 29 Jan 2021 10:43:08 +0100https://ask.sagemath.org/question/55490/matrix-multiplication-with-a-vector-in-euclideanspace/?answer=55493#post-id-55493Comment by curios_mind for <p>You have to convert the matrix <code>M</code> to an endomorphism of the Euclidean space and apply the latter to the vector field. Given the canonical identification between endomorphisms and tensors of type (1,1), the conversion is performed as follows:</p>
<pre><code>A = E.tensor_field(1, 1, M)
</code></pre>
<p>Here is the full example:</p>
<pre><code>sage: E.<x,y,z> = EuclideanSpace(start_index=0)
sage: vf = E.vector_field([x*y, x^2, z**2])
sage: M = Matrix(RR, 3, 3); M[:] = 1
sage: A = E.tensor_field(1, 1, M)
sage: A
Tensor field of type (1,1) on the Euclidean space E^3
sage: A[:]
[1 1 1]
[1 1 1]
[1 1 1]
sage: A(vf)
Vector field on the Euclidean space E^3
sage: A(vf).display()
(x^2 + x*y + z^2) e_x + (x^2 + x*y + z^2) e_y + (x^2 + x*y + z^2) e_z
sage: A(vf)[:]
[x^2 + x*y + z^2, x^2 + x*y + z^2, x^2 + x*y + z^2]
</code></pre>
<p>Note that the action of the endomorphism <code>A</code> onto the vector field <code>vf</code> is obtained by <code>A(vf)</code> and not by <code>A*vf</code>, which would perform a tensor product and would yield a tensor field of type (2, 1). </p>
<p>Note also that if the matrix <code>M</code> is invertible, you may perform the conversion simply as</p>
<pre><code>A = E.automorphism_field(M)
</code></pre>
https://ask.sagemath.org/question/55490/matrix-multiplication-with-a-vector-in-euclideanspace/?comment=55495#post-id-55495Thank you very much. This really helped and saved me from a lot of trouble.Fri, 29 Jan 2021 14:26:30 +0100https://ask.sagemath.org/question/55490/matrix-multiplication-with-a-vector-in-euclideanspace/?comment=55495#post-id-55495