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
On Mon, Mar 6, 2017 at 3:45 PM, <[email protected]> wrote:
> 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
>
>
> --
> 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 [email protected].
> To post to this group, send email to [email protected].
> 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.
--
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 [email protected].
To post to this group, send email to [email protected].
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/CAKgW%3D6Ju6j_MbMa56Dg4RAo11unR93Pnn%2BfVh8B9xbY-KWf%2BiA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.