Ask Your Question

Jean-Sébastien's profile - activity

2023-04-27 23:30:52 +0100 received badge  Famous Question (source)
2020-12-14 20:57:28 +0100 received badge  Notable Question (source)
2020-08-12 08:45:45 +0100 received badge  Popular Question (source)
2019-11-08 17:49:54 +0100 commented answer Trigonometric simplifications and matrices

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

2019-11-08 15:53:53 +0100 received badge  Editor (source)
2019-11-08 15:53:07 +0100 asked a question 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 .

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?

2019-09-11 20:29:33 +0100 received badge  Nice Question (source)
2019-09-10 20:01:06 +0100 received badge  Scholar (source)
2019-09-10 19:55:05 +0100 commented answer Substitution of free variable

This should work. I think I should be able to adapt it if there are more than 1 free variable as well

2019-09-10 19:39:40 +0100 received badge  Student (source)
2019-09-10 19:34:53 +0100 asked a question Substitution of free variable

I have sagecells on a page that are used to solve some equations. In a further cell, I want to substitute a given value in place of a free variable. Sage's free variables have names such as r1, r2, etc.

Is there a way (some kind of wildcard) to substitute a value for a free variable without knowing its name? I'd like this because depending on the order of execution a user would press the cells, the names would change.

It would look like this

CELL1

sol1 = solve([x + y == 1], x, y)

CELL2

sol2 = solve([x - y == 3], x, y)

and then further down I would like a new cell that would substitute the free variable in sol1 to a given value, say 0.

However if I use something along the line of

sol1part = sol1.substitute(r1=0)

and the user executed for some reason cell2 before cell1, it will not work.

2014-02-11 00:24:16 +0100 asked a question solve() and square roots

Why can't Sage solve equations of the type x-sqrt(x)=0. Here is what I get

solve(x-sqrt(x)==0,x)
[x == sqrt(x)]

It does not have any problems solving sqrt(x)=5, giving

 solve(sqrt(x)==5,x)
   [x == 25]
2014-02-06 17:50:26 +0100 commented answer Plotting in Ubuntu 12.10

This worked for me

2014-02-06 17:50:15 +0100 received badge  Supporter (source)