expr.atoms(sin, cos) might be what you want.
Help on method atoms in module sympy.core.basic:
atoms(self, *types) unbound sympy.core.expr.Expr method
Returns the atoms that form the current object.
By default, only objects that are truly atomic and can't
be divided into smaller pieces are returned: symbols, numbers,
and number symbols like I and pi. It is possible to request
atoms of any type, however, as demonstrated below.
[...]
In [17]: e = a + b + c*sin(x) + d*cos(x+y) + a*sin(z)**2*cos(2*z)
In [18]: e.atoms(sin, cos)
Out[18]: set(sin(x), sin(z), cos(2⋅z), cos(x + y))
On 21.07.2011 16:14, Bastian Weber wrote:
Hi all,
I have an expression like:
e = a + b + c*sin(x) + d*cos(x+y) + e*sin(z)**2*cos(2*z)
and I want to produce a list where just the calls to sin and cos are
collected:
desired_result = [sin(x), cos(x+y), sin(z), cos(2*z)]
Alternatively, the arguments would be sufficient:
desired_result2 = [x, x+y, z, 2*z]
I tried it with pattern matching but without success.
I think there is an elegant and short way to do it but I do not see it
right now...
Thanks.
Bastian
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sympy?hl=en.