@@ -17,7 +17,7 @@ immutable TrapezoidalEvenFast <: IntegrationMethod end
1717immutable SimpsonEven <: IntegrationMethod end # https://en.wikipedia.org/wiki/Simpson%27s_rule#Alternative_extended_Simpson.27s_rule
1818immutable SimpsonEvenFast <: IntegrationMethod end
1919
20- function integrate {X<:Real , Y<:Real } (x:: AbstractVector{X} , y:: AbstractVector{Y} , :: Trapezoidal )
20+ function integrate {X<:Number , Y<:Number } (x:: AbstractVector{X} , y:: AbstractVector{Y} , :: Trapezoidal )
2121 @assert length (x) == length (y) " x and y vectors must be of the same length!"
2222 retval = zero (promote (x[1 ], y[1 ])[1 ])
2323 for i in 1 : length (y)- 1
@@ -26,20 +26,20 @@ function integrate{X<:Real, Y<:Real}(x::AbstractVector{X}, y::AbstractVector{Y},
2626 return 0.5 * retval
2727end
2828
29- function integrate {X<:Real , Y<:Real } (x:: AbstractVector{X} , y:: AbstractVector{Y} , :: TrapezoidalEven )
29+ function integrate {X<:Number , Y<:Number } (x:: AbstractVector{X} , y:: AbstractVector{Y} , :: TrapezoidalEven )
3030 @assert length (x) == length (y) " x and y vectors must be of the same length!"
3131 return 0.5 * (x[end ] - x[1 ]) / (length (y) - 1 ) * (y[1 ] + y[end ] + sum (y[2 : end - 1 ]))
3232end
3333
34- function integrate {X<:Real , Y<:Real } (x:: AbstractVector{X} , y:: AbstractVector{Y} , :: TrapezoidalFast )
34+ function integrate {X<:Number , Y<:Number } (x:: AbstractVector{X} , y:: AbstractVector{Y} , :: TrapezoidalFast )
3535 retval = zero (promote (x[1 ], y[1 ])[1 ])
3636 @fastmath @simd for i in 1 : length (y)- 1
3737 @inbounds retval += (x[i+ 1 ] - x[i]) * (y[i] + y[i+ 1 ])
3838 end
3939 return 0.5 * retval
4040end
4141
42- function integrate {X<:Real , Y<:Real } (x:: AbstractVector{X} , y:: AbstractVector{Y} , :: TrapezoidalEvenFast )
42+ function integrate {X<:Number , Y<:Number } (x:: AbstractVector{X} , y:: AbstractVector{Y} , :: TrapezoidalEvenFast )
4343 retval = zero (promote (x[1 ], y[1 ])[1 ])
4444 N = length (y) - 1
4545 @fastmath @simd for i in 2 : N
@@ -48,7 +48,7 @@ function integrate{X<:Real, Y<:Real}(x::AbstractVector{X}, y::AbstractVector{Y},
4848 @inbounds return (x[end ] - x[1 ]) / N * (retval + 0.5 * y[1 ] + 0.5 * y[end ])
4949end
5050
51- function integrate {X<:Real , Y<:Real } (x:: AbstractVector{X} , y:: AbstractVector{Y} , :: SimpsonEven )
51+ function integrate {X<:Number , Y<:Number } (x:: AbstractVector{X} , y:: AbstractVector{Y} , :: SimpsonEven )
5252 @assert length (x) == length (y) " x and y vectors must be of the same length!"
5353 retval = (17 * y[1 ] + 59 * y[2 ] + 43 * y[3 ] + 49 * y[4 ] + 49 * y[end - 3 ] + 43 * y[end - 2 ] + 59 * y[end - 1 ] + 17 * y[end ]) / 48
5454 for i in 5 : length (y) - 1
@@ -57,7 +57,7 @@ function integrate{X<:Real, Y<:Real}(x::AbstractVector{X}, y::AbstractVector{Y},
5757 return (x[end ] - x[1 ]) / (length (y) - 1 ) * retval
5858end
5959
60- function integrate {X<:Real , Y<:Real } (x:: AbstractVector{X} , y:: AbstractVector{Y} , :: SimpsonEvenFast )
60+ function integrate {X<:Number , Y<:Number } (x:: AbstractVector{X} , y:: AbstractVector{Y} , :: SimpsonEvenFast )
6161 @inbounds retval = 17 * y[1 ] + 59 * y[2 ] + 43 * y[3 ] + 49 * y[4 ]
6262 @inbounds retval += 49 * y[end - 3 ] + 43 * y[end - 2 ] + 59 * y[end - 1 ] + 17 * y[end ]
6363 retval /= 48
@@ -67,6 +67,6 @@ function integrate{X<:Real, Y<:Real}(x::AbstractVector{X}, y::AbstractVector{Y},
6767 @inbounds return (x[end ] - x[1 ]) / (length (y) - 1 ) * retval
6868end
6969
70- integrate {X<:Real , Y<:Real } (x:: AbstractVector{X} , y:: AbstractVector{Y} ) = integrate (x, y, TrapezoidalFast ())
70+ integrate {X<:Number , Y<:Number } (x:: AbstractVector{X} , y:: AbstractVector{Y} ) = integrate (x, y, TrapezoidalFast ())
7171
7272end
0 commit comments