Ask Your Question
1

Unexpected results defining a scalar field

asked 2023-01-22 23:35:08 +0100

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.

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
1

answered 2023-01-23 09:18:09 +0100

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).

edit flag offensive delete link more

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 $\mathbb{R}^3$ 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 ( 2023-01-23 09:56:54 +0100 )edit

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 ( 2023-01-23 10:03:22 +0100 )edit

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 ( 2023-01-23 10:29:30 +0100 )edit
1

answered 2023-01-23 10:38:16 +0100

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)
edit flag offensive delete link more

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: 2023-01-22 23:35:08 +0100

Seen: 163 times

Last updated: Jan 23 '23