# vector_field.apply_map before and after vector.display (weird behaviour)

Hello,

Recently, I have come a cross a very weird behaviour with vector_field.apply_map function. Here is the case:

Consider the following code:

E.<r,th,ph>=EuclideanSpace(coordinates="spherical",start_index=0)

cart.<x,y,z>=E.cartesian_coordinates()
cartf=E.cartesian_frame()

spherf=E.spherical_frame()

E.set_default_frame(cartf)


Now, if I create a vector field, substitute ph with ph_1 and th with th_1, and then display the resultant vector as

var("r_1 th_1 ph_1")
v=E.vector_field([r_1,0,0], frame=spherf, chart=cart);
v.apply_map(lambda c:c.subs(ph==ph_1, th==th_1));show(v.display())


I get 0 printed

However,

If I do the same, but this time if I add show(v.display()) before calling apply_map function as

var("r_1 th_1 ph_1")
v=E.vector_field([r_1,0,0], frame=spherf, chart=cart); show(v.display())
v.apply_map(lambda c:c.subs(ph==ph_1, th==th_1));show(v.display())


I get

 r_1 cos(ph)sin(th) e_x + r_1 sin(ph)sin(th) e_y + r_1 cos(th) e_z
r_1 cos(ph_1)sin(th_1) e_x + r_1 sin(ph_1)sin(th_1) e_y + r_1 cos(th_1) e_z


printed (as expected).

Why does the display function affect the substitution?

edit retag close merge delete

Sort by » oldest newest most voted

Well, I would say that this is caused by a somewhat strange operation that you are asking for. When you write

v = E.vector_field([r_1,0,0], frame=spherf, chart=cart)
v.apply_map(lambda c:c.subs(ph==ph_1, th==th_1))


you are initializing the vector field with components in the frame spherf (orthonormal frame associated with spherical coordinates), while the second line asks for an apply_map in the default frame, which is cartf. But at this stage, such components are not known. Such a substitution is thus not very meaningful. If you add v.display() before v.apply_map, as in your second example, this triggers the computation of the components with respect to cartf, so that the substitution becomes meaningful. If you want to stick to the first example, then you should enforce apply_map to act on the components w.r.t spherf, by adding the argument frame=spherf:

v = E.vector_field([r_1,0,0], frame=spherf, chart=cart)
v.apply_map(lambda c:c.subs(ph==ph_1, th==th_1), frame=spherf)


Then everything is OK.

more

Your explanation makes sense, though I thought when the vector_field is called, as in the question, the corresponding representation of the field in spherical chart is updated.

( 2021-02-08 15:05:08 +0200 )edit