In fu.py there are several functions to manipulate trigonometric 
expressions; in your example you
can use TR8  to expand products of sin-cos to sums;

```
from sympy.simplify.fu import TR8
from sympy.simplify.simplify import _mexpand
P = (D + F*sin(x) + G*cos(x) + H*sin(2*x) + J*cos(2*x))**2
r = _mexpand(TR8(_mexpand(P)))
```
what is missing is the collection of the coefficients; it is easy to write 
a function collecting terms,
but I suspect that there is already a simple way in SymPy to do this.



On Friday, February 7, 2014 8:28:20 AM UTC+1, Alex Clifton wrote:
>
> I was wondering if there was a way to “guide” sympy in performing trig 
> identities to get the output into a specific form? Below, I go into detail 
> and have attached a working version of the file for reference.
>
> In the expression of P, the coefficients D, F, G, H, and J are assumed to 
> be real valued. I have left some commented print statements to show the 
> different simplify options I have tried. I have performed this calculation 
> by hand and I know there are several trig substitutions that need to be 
> made in order to get the final expression in the form that I would like. 
> That form is to get rid of all powers of trig functions greater than 1 by 
> appropriate substitutions. Of course, I cannot expect sympy to know that I 
> want things in this form so I am not surprised when the different simplify 
>  statements do not give me that form. I was wondering what would be the 
> best way to guide sympy in order to get the final output of P to be in the 
> following form:
>
> K + Lsin(x) + Mcos(x) +  Nsin(2x) + Qcos(2x) + Rsin(3x) + Scos(3x) + 
> Tsin(4x) + Vcos(4x)
>
> Where K, L, M, N, Q, R, S, T, and V are now combinations of the original 
> D, F, G, H, and J.
>
> By the way, I am not as concerned now about the coefficients as I am 
> getting rid of the higher powers of the trig functions. Although if people 
> would like to weigh in on that, that would be great. If more detail is 
> needed, please let me know and I’d be happy to provide it.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sympy+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to