Ask Your Question
0

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

asked 2021-02-07 04:27:55 +0200

curios_mind gravatar image

updated 2021-02-07 04:48:00 +0200

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 flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-02-07 11:33:25 +0200

eric_g gravatar image

updated 2021-02-07 11:52:00 +0200

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.

edit flag offensive delete link more

Comments

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.

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

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: 2021-02-07 04:27:55 +0200

Seen: 58 times

Last updated: Feb 07