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.Tue, 06 Dec 2016 14:14:17 +0100Solving large trigonometric fucntionshttps://ask.sagemath.org/question/35705/solving-large-trigonometric-fucntions/Hi everyone,
I'm new to sage and would like to use it to give me an exact solution to the derivative of a large trig function. I have been tinkering around with the different trig simplification routines to no avail. Here is the current incarnation of my code:
var("theta phi r I sigma_a1 sigma_a2 M_1 M_2 F_tu")
import sympy as sy
M1(phi)=M_1*cos(phi+pi/2)
M1=M1.trig_reduce()
M2(phi)=M_2*cos(phi+theta+pi/2)
M2=M2.trig_reduce()
sigma_b1(r,phi)=M1(phi - pi/2)*r/I+sigma_a1
sigma_b1=sigma_b1.trig_reduce()
sigma_b2(r,phi)=M2(phi - pi/2)*r/I+sigma_a2
sigma_b2=sigma_b2.trig_reduce()
sigma_alt(r,phi)=sigma_b1-sigma_b2
sigma_alt=sigma_alt.trig_reduce()
sigma_mean(r,phi)=(sigma_b1-sigma_b2)/2
sigma_mean=sigma_mean.trig_reduce()
sigma_alteq(r,phi)=F_tu*sigma_alt/(F_tu-sigma_mean)
sigma_alteq=sigma_alteq.trig_reduce()
sol=diff(sigma_alteq,phi)
sol_reduc=SR(sy.fu(sy.sympify(sol))); sol_reduc
show(sol_reduc)
solve(sol_reduc,phi)
Sorry, I do not know how to make the code appear in a window. The final result it gives me is:
[sin(phi + theta) == M_1*sin(phi)/M_2]
Can someone please help me or at least point me in the right direction. Thanks.Wed, 23 Nov 2016 21:33:39 +0100https://ask.sagemath.org/question/35705/solving-large-trigonometric-fucntions/Comment by tmonteil for <p>Hi everyone,</p>
<p>I'm new to sage and would like to use it to give me an exact solution to the derivative of a large trig function. I have been tinkering around with the different trig simplification routines to no avail. Here is the current incarnation of my code:</p>
<pre><code>var("theta phi r I sigma_a1 sigma_a2 M_1 M_2 F_tu")
import sympy as sy
M1(phi)=M_1*cos(phi+pi/2)
M1=M1.trig_reduce()
M2(phi)=M_2*cos(phi+theta+pi/2)
M2=M2.trig_reduce()
sigma_b1(r,phi)=M1(phi - pi/2)*r/I+sigma_a1
sigma_b1=sigma_b1.trig_reduce()
sigma_b2(r,phi)=M2(phi - pi/2)*r/I+sigma_a2
sigma_b2=sigma_b2.trig_reduce()
sigma_alt(r,phi)=sigma_b1-sigma_b2
sigma_alt=sigma_alt.trig_reduce()
sigma_mean(r,phi)=(sigma_b1-sigma_b2)/2
sigma_mean=sigma_mean.trig_reduce()
sigma_alteq(r,phi)=F_tu*sigma_alt/(F_tu-sigma_mean)
sigma_alteq=sigma_alteq.trig_reduce()
sol=diff(sigma_alteq,phi)
sol_reduc=SR(sy.fu(sy.sympify(sol))); sol_reduc
show(sol_reduc)
solve(sol_reduc,phi)
</code></pre>
<p>Sorry, I do not know how to make the code appear in a window. The final result it gives me is:</p>
<p>[sin(phi + theta) == M_1*sin(phi)/M_2]</p>
<p>Can someone please help me or at least point me in the right direction. Thanks.</p>
https://ask.sagemath.org/question/35705/solving-large-trigonometric-fucntions/?comment=35709#post-id-35709Could you please tell us which result would you expect ?Thu, 24 Nov 2016 02:10:39 +0100https://ask.sagemath.org/question/35705/solving-large-trigonometric-fucntions/?comment=35709#post-id-35709Comment by slelievre for <p>Hi everyone,</p>
<p>I'm new to sage and would like to use it to give me an exact solution to the derivative of a large trig function. I have been tinkering around with the different trig simplification routines to no avail. Here is the current incarnation of my code:</p>
<pre><code>var("theta phi r I sigma_a1 sigma_a2 M_1 M_2 F_tu")
import sympy as sy
M1(phi)=M_1*cos(phi+pi/2)
M1=M1.trig_reduce()
M2(phi)=M_2*cos(phi+theta+pi/2)
M2=M2.trig_reduce()
sigma_b1(r,phi)=M1(phi - pi/2)*r/I+sigma_a1
sigma_b1=sigma_b1.trig_reduce()
sigma_b2(r,phi)=M2(phi - pi/2)*r/I+sigma_a2
sigma_b2=sigma_b2.trig_reduce()
sigma_alt(r,phi)=sigma_b1-sigma_b2
sigma_alt=sigma_alt.trig_reduce()
sigma_mean(r,phi)=(sigma_b1-sigma_b2)/2
sigma_mean=sigma_mean.trig_reduce()
sigma_alteq(r,phi)=F_tu*sigma_alt/(F_tu-sigma_mean)
sigma_alteq=sigma_alteq.trig_reduce()
sol=diff(sigma_alteq,phi)
sol_reduc=SR(sy.fu(sy.sympify(sol))); sol_reduc
show(sol_reduc)
solve(sol_reduc,phi)
</code></pre>
<p>Sorry, I do not know how to make the code appear in a window. The final result it gives me is:</p>
<p>[sin(phi + theta) == M_1*sin(phi)/M_2]</p>
<p>Can someone please help me or at least point me in the right direction. Thanks.</p>
https://ask.sagemath.org/question/35705/solving-large-trigonometric-fucntions/?comment=35712#post-id-35712@Kevin_Bryant
To display blocks of code, either indent them with 4 spaces,
or select the corresponding lines and click the "code" button
(the icon with '101 010').
Can you edit your question to do that?Thu, 24 Nov 2016 10:56:04 +0100https://ask.sagemath.org/question/35705/solving-large-trigonometric-fucntions/?comment=35712#post-id-35712Comment by Kevin Bryant for <p>Hi everyone,</p>
<p>I'm new to sage and would like to use it to give me an exact solution to the derivative of a large trig function. I have been tinkering around with the different trig simplification routines to no avail. Here is the current incarnation of my code:</p>
<pre><code>var("theta phi r I sigma_a1 sigma_a2 M_1 M_2 F_tu")
import sympy as sy
M1(phi)=M_1*cos(phi+pi/2)
M1=M1.trig_reduce()
M2(phi)=M_2*cos(phi+theta+pi/2)
M2=M2.trig_reduce()
sigma_b1(r,phi)=M1(phi - pi/2)*r/I+sigma_a1
sigma_b1=sigma_b1.trig_reduce()
sigma_b2(r,phi)=M2(phi - pi/2)*r/I+sigma_a2
sigma_b2=sigma_b2.trig_reduce()
sigma_alt(r,phi)=sigma_b1-sigma_b2
sigma_alt=sigma_alt.trig_reduce()
sigma_mean(r,phi)=(sigma_b1-sigma_b2)/2
sigma_mean=sigma_mean.trig_reduce()
sigma_alteq(r,phi)=F_tu*sigma_alt/(F_tu-sigma_mean)
sigma_alteq=sigma_alteq.trig_reduce()
sol=diff(sigma_alteq,phi)
sol_reduc=SR(sy.fu(sy.sympify(sol))); sol_reduc
show(sol_reduc)
solve(sol_reduc,phi)
</code></pre>
<p>Sorry, I do not know how to make the code appear in a window. The final result it gives me is:</p>
<p>[sin(phi + theta) == M_1*sin(phi)/M_2]</p>
<p>Can someone please help me or at least point me in the right direction. Thanks.</p>
https://ask.sagemath.org/question/35705/solving-large-trigonometric-fucntions/?comment=35730#post-id-35730@tmonteil I was expecting a set of 4 solutions over the interval of 0 to 2*pi for phi. I solved this problem earlier on Wolframalpha before I added the terms sigma_a1 and sigma_a2 to my equations and got the following for one solution (note that variable names are different but the problem was essentially the same)
t = -cos^(-1)((-sqrt((2 F X Y^2 Z cos(2 a) - 2 F X Y^2 Z)^2 - 4 (-4 F^2 X Y cos(a) + 2 F^2 X^2 + 2 F^2 Y^2) (4 F^2 X Y cos(a) - F^2 Y^2 cos(2 a) - X^2 Y^2 Z^2 cos(2 a) - 2 F^2 X^2 - F^2 Y^2 + X^2 Y^2 Z^2)) - 2 F X Y^2 Z cos(2 a) + 2 F X Y^2 Z)/(2 (-4 F^2 X Y cos(a) + 2 F^2 X^2 + 2 F^2 Y^2)))
I tested these solutions provided by Wolframalpha and they were correct, so I was expecting something along the same lines here.Thu, 24 Nov 2016 22:43:34 +0100https://ask.sagemath.org/question/35705/solving-large-trigonometric-fucntions/?comment=35730#post-id-35730Comment by Kevin Bryant for <p>Hi everyone,</p>
<p>I'm new to sage and would like to use it to give me an exact solution to the derivative of a large trig function. I have been tinkering around with the different trig simplification routines to no avail. Here is the current incarnation of my code:</p>
<pre><code>var("theta phi r I sigma_a1 sigma_a2 M_1 M_2 F_tu")
import sympy as sy
M1(phi)=M_1*cos(phi+pi/2)
M1=M1.trig_reduce()
M2(phi)=M_2*cos(phi+theta+pi/2)
M2=M2.trig_reduce()
sigma_b1(r,phi)=M1(phi - pi/2)*r/I+sigma_a1
sigma_b1=sigma_b1.trig_reduce()
sigma_b2(r,phi)=M2(phi - pi/2)*r/I+sigma_a2
sigma_b2=sigma_b2.trig_reduce()
sigma_alt(r,phi)=sigma_b1-sigma_b2
sigma_alt=sigma_alt.trig_reduce()
sigma_mean(r,phi)=(sigma_b1-sigma_b2)/2
sigma_mean=sigma_mean.trig_reduce()
sigma_alteq(r,phi)=F_tu*sigma_alt/(F_tu-sigma_mean)
sigma_alteq=sigma_alteq.trig_reduce()
sol=diff(sigma_alteq,phi)
sol_reduc=SR(sy.fu(sy.sympify(sol))); sol_reduc
show(sol_reduc)
solve(sol_reduc,phi)
</code></pre>
<p>Sorry, I do not know how to make the code appear in a window. The final result it gives me is:</p>
<p>[sin(phi + theta) == M_1*sin(phi)/M_2]</p>
<p>Can someone please help me or at least point me in the right direction. Thanks.</p>
https://ask.sagemath.org/question/35705/solving-large-trigonometric-fucntions/?comment=35731#post-id-35731@slelievre thanks and doneThu, 24 Nov 2016 22:44:25 +0100https://ask.sagemath.org/question/35705/solving-large-trigonometric-fucntions/?comment=35731#post-id-35731Answer by mforets for <p>Hi everyone,</p>
<p>I'm new to sage and would like to use it to give me an exact solution to the derivative of a large trig function. I have been tinkering around with the different trig simplification routines to no avail. Here is the current incarnation of my code:</p>
<pre><code>var("theta phi r I sigma_a1 sigma_a2 M_1 M_2 F_tu")
import sympy as sy
M1(phi)=M_1*cos(phi+pi/2)
M1=M1.trig_reduce()
M2(phi)=M_2*cos(phi+theta+pi/2)
M2=M2.trig_reduce()
sigma_b1(r,phi)=M1(phi - pi/2)*r/I+sigma_a1
sigma_b1=sigma_b1.trig_reduce()
sigma_b2(r,phi)=M2(phi - pi/2)*r/I+sigma_a2
sigma_b2=sigma_b2.trig_reduce()
sigma_alt(r,phi)=sigma_b1-sigma_b2
sigma_alt=sigma_alt.trig_reduce()
sigma_mean(r,phi)=(sigma_b1-sigma_b2)/2
sigma_mean=sigma_mean.trig_reduce()
sigma_alteq(r,phi)=F_tu*sigma_alt/(F_tu-sigma_mean)
sigma_alteq=sigma_alteq.trig_reduce()
sol=diff(sigma_alteq,phi)
sol_reduc=SR(sy.fu(sy.sympify(sol))); sol_reduc
show(sol_reduc)
solve(sol_reduc,phi)
</code></pre>
<p>Sorry, I do not know how to make the code appear in a window. The final result it gives me is:</p>
<p>[sin(phi + theta) == M_1*sin(phi)/M_2]</p>
<p>Can someone please help me or at least point me in the right direction. Thanks.</p>
https://ask.sagemath.org/question/35705/solving-large-trigonometric-fucntions/?answer=35930#post-id-35930It seems to me that the hard work is already done properly by the solver. Finally, you got:
sage: var("theta phi M_1 M_2")
sage: f = (sin(theta+phi)-M_1/M_2*sin(phi)).simplify_full()
sage: f, solve(f, phi)
Which is:
$$
\newcommand{\Bold}[1]{\mathbf{#1}}\left(\frac{{\left(\cos\left(\theta\right) \sin\left(\phi\right) + \cos\left(\phi\right) \sin\left(\theta\right)\right)} M_{2} - M_{1} \sin\left(\phi\right)}{M_{2}}, \left[\sin\left(\phi\right) = -\frac{M_{2} \cos\left(\phi\right) \sin\left(\theta\right)}{M_{2} \cos\left(\theta\right) - M_{1}}\right]\right)
$$
Hence, the solution for $\phi$ is obtianed by intersecting the tangent function with a constant line, and by periodicity we can reason in the interval $[-\pi, \pi]$, recall that:
![tangent function](http://mathworld.wolfram.com/images/eps-gif/Tangent_701.gif)
- if $\theta$ is an integer multiple of $\pi$, then $\{0,\pm \pi\}$ is the solution set.
- in general, there are exactly $2$ intersections (and the solutions differ by $\pi$).
- if the values of $M_1$ and $M_2$ allow it ($|M_1/M_2| \leq 1$), then there exists a value of $\theta$ for which the denominator vanishes, but the solution set is $\pm \pi/2$.
*Remark.* I'd be interested to know if there is a way to do this sort of "case study" automatically. I tried with some solver options (explicit, etc.), but it doesn't help. Neither with SymPy solve or the new [solveset](http://docs.sympy.org/latest/modules/solvers/solveset.html).. but maybe I'm missing to pass some extra information.Tue, 06 Dec 2016 14:14:17 +0100https://ask.sagemath.org/question/35705/solving-large-trigonometric-fucntions/?answer=35930#post-id-35930