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.Mon, 18 May 2020 19:00:15 +0200Trig simplification of implicit functions failshttps://ask.sagemath.org/question/51442/trig-simplification-of-implicit-functions-fails/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/Mon, 18 May 2020 04:25:54 +0200https://ask.sagemath.org/question/51442/trig-simplification-of-implicit-functions-fails/Answer by tmonteil for <p>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.</p>
<p>For example, this all works fine:</p>
<pre><code>var('z')
r = cos(z)**2 + sin(z)**2
assert r.simplify_trig() == 1
</code></pre>
<p>However, when z is a function of time, things break down entirely:</p>
<pre><code>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
</code></pre>
<p>Specifically, <code>K.simplify_trig()</code> throws:</p>
<blockquote>
<p>TypeError: ECL says: THROW: The catch MACSYMA-QUIT is undefined.</p>
</blockquote>
<p>I would also expect </p>
<pre><code>assert K.substitute_function(θ1, z) == cos(z)^2 + sin(z)^2
</code></pre>
<p>However <code>K.substitute_function(θ1, z)</code> just gives me K unchanged.</p>
<p>Seems related, but I'm still stumped: ask.sagemath.org/question/7856/lagranian-mechanics/</p>
https://ask.sagemath.org/question/51442/trig-simplification-of-implicit-functions-fails/?answer=51447#post-id-51447As 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
Mon, 18 May 2020 19:00:15 +0200https://ask.sagemath.org/question/51442/trig-simplification-of-implicit-functions-fails/?answer=51447#post-id-51447