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.Fri, 08 Nov 2019 15:53:07 +0100Trigonometric 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/reduce_trig for matriceshttps://ask.sagemath.org/question/7834/reduce_trig-for-matrices/I am trying to reduce the trig functions of the following symbolic matrix:
[ sin(1/2*B)*cos(1/2*B) I*sin(1/2*B)^2 - 1/2*I]
[-I*sin(1/2*B)^2 + 1/2*I -sin(1/2*B)*cos(1/2*B)]
I expect:
[1/2*sin(B), -1/2*I*cos(B)]
[1/2*I*cos(B), -1/2*sin(B)]
But get:
Traceback (click to the left of this block for traceback)
...
AttributeError: 'sage.matrix.matrix_symbolic_dense.Matrix_symbolic_dense' object has no attribute
'reduce_trig'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "_sage_input_170.py", line 10, in <module>
exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("KFJ4KEIpKkl5KlJ4KC1CKSkucmVkdWNlX3RyaWcoKQ=="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
File "", line 1, in <module>
File "/tmp/tmpTc7DZX/___code___.py", line 2, in <module>
exec compile(u'(Rx(B)*Iy*Rx(-B)).reduce_trig()
File "", line 1, in <module>
File "element.pyx", line 306, in sage.structure.element.Element.__getattr__ (sage/structure/element.c:2666)
File "parent.pyx", line 272, in sage.structure.parent.getattr_from_other_class (sage/structure/parent.c:2840)
What am I doing wrong?
Thank you for your help.
mhfreyWed, 29 Dec 2010 12:24:53 +0100https://ask.sagemath.org/question/7834/