Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Heaviside function #14981

Closed
pabloferz opened this issue Feb 7, 2016 · 5 comments
Closed

Heaviside function #14981

pabloferz opened this issue Feb 7, 2016 · 5 comments

Comments

@pabloferz
Copy link
Contributor

Would it be too much to have a heavisidefunction in base? Something like

heaviside(x::AbstractFloat) = ifelse(x < 0, zero(x), ifelse(x > 0, one(x), oftype(x,0.5)))
@jiahao
Copy link
Member

jiahao commented Feb 8, 2016

I suppose so, but I don't really see much use for Heaviside functions in numerical code. Any good examples of when you'd use it in practice?

@pabloferz
Copy link
Contributor Author

I don't have any good example. I have used the SymPy's to write some superpositions of planewaves.

The real reason I was thinking of having one is beacuase I was writing a printing method in SymPy to generate the equivalent Julia form. I guess it makes more sense to have the function in SymPy.jl to allow the translation of symbolic expressions to fast Julia methods.

@mschauer
Copy link
Contributor

mschauer commented Feb 8, 2016

The function is mostly used as distribution, where it does not matter which value it takes at zero. A symbolic integration package might define heaviside as formal object. But I don't think it is needed as a real function

@pabloferz
Copy link
Contributor Author

Of course, it is not needed as a real function. As I said, it was motivated from the idea to translate SymPy to Julia code and it probably makes more sense over SymPy.jl than in Base. I'll close this.

@moustachio-belvedere
Copy link

In case this is still of interest to anyone, a numerical example where a library piecewise function would be nice (I'm fitting to this function today):

https://www.ncbi.nlm.nih.gov/pmc/articles/PMC2744968/

See equation 2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants