Skip to content

Commit

Permalink
fix integration
Browse files Browse the repository at this point in the history
  • Loading branch information
EigenSolver committed Aug 27, 2024
1 parent 56b1b83 commit 310c075
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/integration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ increment `h`
"""
function integrate(y::ArrayOrSubArray{<:Real,1}, h::Real; method::Symbol=:simpson)::Real
n = length(y) - 1
if n%2==1
println("warning: `y` length (number of intervals) must be odd, switching to first order integration.")
method=:trapezoid
end

if method == :simpson
n % 2 == 0 || error("`y` length (number of intervals) must be odd")
# n % 2 == 0 || error("`y` length (number of intervals) must be odd")
s = sum(y[1:2:n] + 4 * y[2:2:n] + y[3:2:n+1])
return h / 3 * s
elseif method == :trapezoid
Expand Down

0 comments on commit 310c075

Please sign in to comment.