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.Sun, 07 Feb 2021 04:27:55 +0100vector_field.apply_map before and after vector.display (weird behaviour)https://ask.sagemath.org/question/55611/vector_fieldapply_map-before-and-after-vectordisplay-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?curios_mindSun, 07 Feb 2021 04:27:55 +0100https://ask.sagemath.org/question/55611/Trigonometric simplifications and matriceshttps://ask.sagemath.org/question/48674/trigonometric-simplifications-and-matrices/I want to simplify trigonometric identities in a matrix. For example, say I want to show that the composition of two rotation matrices is a rotation, I can do with sage something like
> var("theta1,theta2")
Rtheta1=column_matrix([[cos(theta1),sin(theta1)],[-sin(theta1),cos(theta1)]])
Rtheta2=column_matrix([[cos(theta2),sin(theta2)],[-sin(theta2),cos(theta2)]])
produit=Rtheta1*Rtheta2
show(produit.simplify_trig())
show(produit.apply_map(lambda x: x.trig_reduce()))
Note that `simplify_trig` or `trig_reduce` don't work on matrices and that you need to use `apply_map` to use it entry by entry, as detailed in Mike Hansen's answer in [this question](https://ask.sagemath.org/question/7773/is-there-a-way-to-simplify_full-and-trig_reduce-a-matrix/) .
However when I get to 3 matrices, sage can't simplify with the above procedure:
> var("theta1,theta2,theta3")
Rtheta1=column_matrix([[cos(theta1),sin(theta1)],[-sin(theta1),cos(theta1)]])
Rtheta2=column_matrix([[cos(theta2),sin(theta2)],[-sin(theta2),cos(theta2)]])
Rtheta3=column_matrix([[cos(theta3),sin(theta3)],[-sin(theta3),cos(theta3)]])
produit=Rtheta1*Rtheta2*Rtheta3
show(produit.apply_map(lambda x: x.trig_reduce()))
For example, the 1-1 entry in this matrix is returned as `cos(theta1 + theta2)*cos(theta3) - sin(theta1 + theta2)*sin(theta3)` .
The weird thing is that using `(cos(theta1 + theta2)*cos(theta3) - sin(theta1 + theta2)*sin(theta3)).trig_reduce()` produces the correct simplification `cos(theta1 + theta2 + theta3)` .
What's happening here? Any other way to force the simplification?Jean-SébastienFri, 08 Nov 2019 15:53:07 +0100https://ask.sagemath.org/question/48674/Is there a way to simplify_full and trig_reduce a matrix?https://ask.sagemath.org/question/7773/is-there-a-way-to-simplify_full-and-trig_reduce-a-matrix/I know I can do it component by component and then construct a matrix out of the output. But it would be nice if I could just say matrix.trig_reduce() and get a matrix with all the components trig_reduced.
Thanks in advance
ShashankThu, 25 Nov 2010 17:54:20 +0100https://ask.sagemath.org/question/7773/