sinc questions

25 views
Skip to first unread message

bonc...@udel.edu

unread,
Mar 6, 2017, 3:53:06 PM3/6/17
to sympy
1. I want to use the "normalized sinc" function (sin(pi x)/(pi x)).  The documentation for sympy 0.7.5 says it exists, but it is not present in sympy 1.0.  Did it disappear?  Or was it never in 0.7.5?

At any rate, I'd prefer the normalized function.  I tried the following:

>>> f = sinc(pi*x)
>>> print(f)
sinc(pi*x)

Evaluating and integrating f seems to give the right answers.  

2. Is there anyway I can get it to print "sinc(x)" instead of "sinc(pi*x)"?  I.e., how do I define my own function with it's own printing methods (including LaTex printing)?

Thanks,

CGB

Aaron Meurer

unread,
Mar 6, 2017, 4:01:03 PM3/6/17
to sy...@googlegroups.com
You can define your own function by subclassing from Function.

Something like

class sinc(Function):
"""
Normalized sinc function.
"""
@classmethod
def eval(cls, x):
# Only evaluate if sinc evaluates
s = sympy.sinc(pi*x)
if not isinstance(s, sinc):
return s/(pi*x)

This will print as sinc() because that's the name of the class. You
have to be careful to not mix up your custom sinc and sympy.sinc.

Depending on what you are doing, you may also need to define methods
like fdiff() to define the derivative. You can see the original
definition of sympy.sinc here
https://github.com/sympy/sympy/blob/163d8cdf4118960a4ea18b33806004e912dbbfe4/sympy/functions/elementary/trigonometric.py#L1712.

Aaron Meurer
> --
> 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+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at https://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/73b9a8a3-d090-4c1e-9bcb-d04af90780ef%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages