Ask Your Question
2

Trig simplification of implicit functions fails

asked 2020-05-18 04:25:54 +0100

calebhyde gravatar image

I'd like to use Sage to verify my solutions to Lagrangian equations of motion for a double pendulum. However, Sage seems unable to handle some basic substitutions needed to make sense of this relatively simple problem.

For example, this all works fine:

var('z')
r = cos(z)**2 + sin(z)**2
assert r.simplify_trig() == 1

However, when z is a function of time, things break down entirely:

var('x,y,t,z')
θ1 = function('θ1')(t)
θ2 = function('θ2')(t)
K = sin(θ1)**2 + cos(θ1)**2
assert K.simplify_trig() == 1

Specifically, K.simplify_trig() throws:

TypeError: ECL says: THROW: The catch MACSYMA-QUIT is undefined.

I would also expect

assert K.substitute_function(θ1, z) == cos(z)^2 + sin(z)^2

However K.substitute_function(θ1, z) just gives me K unchanged.

Seems related, but I'm still stumped: ask.sagemath.org/question/7856/lagranian-mechanics/

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
2

answered 2020-05-18 19:00:15 +0100

tmonteil gravatar image

As for your first question, this is due to the fact that simplification is done by maxima and maxima is not able to deal with unicode symbolic variables. A suggestion is to reserve unicode characters to the Python names and keep ascii strings for symbols:

sage: θ1 = function('theta_1')(t)

Then maxima will be able to handle it correctly, and if you still want to display them with greek letters, you can to

%display latex

so that when you type:

sage: θ1

the output will be $\theta_1(t)$

As fot the second question, you can do:

sage: K.substitute({θ1:z})
cos(z)^2 + sin(z)^2

sage: K = K.substitute({θ1:z})
sage: K
cos(z)^2 + sin(z)^2
sage: K.full_simplify()
1
edit flag offensive delete link more

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: 2020-05-18 04:25:54 +0100

Seen: 241 times

Last updated: May 18 '20