Simpson.jl is a Julia package to integrate y(x) using samples and the composite Simpson’s rule. If x is None, spacing of dx is assumed. If there are an even number of samples, N, then there are an odd number of intervals (N-1), but Simpson’s rule requires an even number of intervals. The parameter ‘even’ controls how this is handled.
The code is based on SciPy v1.7.1
Comments and suggestions are welcome
One thing I would recomend is using
Symbols rather than
Strings for the options. There’s no reason to do string comparison for code like this.
Thanks, I’ll learn about using
Symbols and modify the code.
Looks great for a first package. I especially love the documentation, if only all smaller/obscure packages were this well documented
One suggestion is that instead of using
error you should be more specific with which type of error is being thrown. For example, the first error says:
error("If given, length of x must be the same as y.") which is a problem with the user’s input, so it’s an
Some previous discussion on this can be found here.
I’ve corrected error handling as you suggested.
Your code with
Symbol instead of
String looks like this:
function simpson(y, x=nothing, dx=1.0; even=:avg)
if N % 2 == 0
if even in (:avg, :first)
# Compute using Simpson's rule on last set of intervals
if even in (:avg, :last)
if even === :avg
I could do a PR, but I don’t have a NotABug account.
Done, thanks for the hint!