From 310c0756d3b37bcd3def9c7362a6855f4a7c95f1 Mon Sep 17 00:00:00 2001 From: Yuning Date: Tue, 27 Aug 2024 17:00:30 +0200 Subject: [PATCH] fix integration --- src/integration.jl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/integration.jl b/src/integration.jl index 74c8418..9cf15fd 100644 --- a/src/integration.jl +++ b/src/integration.jl @@ -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