Ask Your Question
1

Trigonometric simplifications and matrices

asked 2019-11-08 15:53:07 +0100

Jean-Sébastien gravatar image

updated 2019-11-08 15:53:53 +0100

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 .

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?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
4

answered 2019-11-08 16:50:23 +0100

tmonteil gravatar image

updated 2019-11-08 16:51:11 +0100

Apparently trig_reduce is not idempotent and you have to apply it twice to get the correct result:

sage: produit.apply_map(lambda x: x.trig_reduce().trig_reduce())
[ cos(theta1 + theta2 + theta3) -sin(theta1 + theta2 + theta3)]
[ sin(theta1 + theta2 + theta3)  cos(theta1 + theta2 + theta3)]
edit flag offensive delete link more

Comments

Wow, what is even more weird is that it seems that if you go with an even number of matrices, sage can simplify with one trig-reduce, but needs two for an odd number of matrices

Jean-Sébastien gravatar imageJean-Sébastien ( 2019-11-08 17:49:54 +0100 )edit

It might depend on how "complex" are the expressions.

tmonteil gravatar imagetmonteil ( 2019-11-08 21:18:29 +0100 )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: 2019-11-08 15:53:07 +0100

Seen: 901 times

Last updated: Nov 08 '19