Processing math: 100%

First time here? Check out the FAQ!

Ask Your Question
1

Unexpected results defining a scalar field

asked 2 years ago

MathMathieu gravatar image

I want to define a scalar field on 3-dimensional Euclidean space that just returns the norm of the length of the vector to the origin. The following attempt fails in a way that I do not understand: note the factor of 2 on the z coordinate!

sage: E = EuclideanSpace(3)
sage: Ecoords = E.cartesian_coordinates()
sage: Ecoords
Chart (E^3, (x, y, z))
sage: E.scalar_field(norm(vector(Ecoords)))
Scalar field on the Euclidean space E^3
sage: scalarfield = E.scalar_field(norm(vector(Ecoords)))
sage: scalarfield.display()
E^3  
(x, y, z)  sqrt(x^2 + y^2 + 2*z^2)

This looks to appear because the z coordinate appears twice in the vectorized coordinates:

sage: vector(Ecoords)
(z, x, y, z)

I could blindly work around this but hoping to understand what is going on.

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
1

answered 2 years ago

vdelecroix gravatar image

Note that the following looks correct

sage: vector(Ecoords[:])
(x, y, z)

I believe that designers of the EuclideanSpace wanted indices to start at 1 and not at 0, as can be seen with

sage: E.start_index()
1

This is definitely confusing in a Python environment (and also error prone as your code snippet shows).

Preview: (hide)
link

Comments

IMHO, vector(Ecoords) should return an error in the first place. Indeed Ecoords is a coordinate chart, i.e. a map from E to R3 and there is no immediate meaning in making it an element of a vector space. On the contrary, Ecoords[:] returns the list of all coordinate symbols and vector(Ecoords[:]) can be viewed as an element of a vector space over the Symbolic Ring.

eric_g gravatar imageeric_g ( 2 years ago )

As for indices starting at 1 and not 0 on an EuclideanSpace, this follows conventions of standard mathematical textbooks, not Python's ones. The Python-like behaviour can be recovered by declaring

E = EuclideanSpace(3, start_index=0)
eric_g gravatar imageeric_g ( 2 years ago )

If we would really want vector(Ecoords) to return a "vector" of the coordinate symbols (and not an error message as suggested in the first comment), we could implement a generator method __iter__ in the class Chart. Then vector(Ecoords) would return (x, y, z) and list(Ecoords) would return [x, y, z].

eric_g gravatar imageeric_g ( 2 years ago )
1

answered 2 years ago

eric_g gravatar image

When dealing with vector fields on an Euclidean space E, you should employ the method E.vector_field() and not the generic function vector(). Back to your example, this gives

sage: E = EuclideanSpace(3)
sage: Ecoords = E.cartesian_coordinates()
sage: Ecoords
Chart (E^3, (x, y, z))
sage: Ecoords[:]
(x, y, z)
sage: v = E.vector_field(Ecoords[:])
sage: v.display()
x e_x + y e_y + z e_z
sage: scalarfield = norm(v)
sage: scalarfield.display()
E^3  
(x, y, z)  sqrt(x^2 + y^2 + z^2)
Preview: (hide)
link

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2 years ago

Seen: 198 times

Last updated: Jan 23 '23