@@ -17,7 +17,7 @@ immutable TrapezoidalEvenFast <: IntegrationMethod end
17
17
immutable SimpsonEven <: IntegrationMethod end # https://en.wikipedia.org/wiki/Simpson%27s_rule#Alternative_extended_Simpson.27s_rule
18
18
immutable SimpsonEvenFast <: IntegrationMethod end
19
19
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 )
21
21
@assert length (x) == length (y) " x and y vectors must be of the same length!"
22
22
retval = zero (promote (x[1 ], y[1 ])[1 ])
23
23
for i in 1 : length (y)- 1
@@ -26,20 +26,20 @@ function integrate{X<:Real, Y<:Real}(x::AbstractVector{X}, y::AbstractVector{Y},
26
26
return 0.5 * retval
27
27
end
28
28
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 )
30
30
@assert length (x) == length (y) " x and y vectors must be of the same length!"
31
31
return 0.5 * (x[end ] - x[1 ]) / (length (y) - 1 ) * (y[1 ] + y[end ] + sum (y[2 : end - 1 ]))
32
32
end
33
33
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 )
35
35
retval = zero (promote (x[1 ], y[1 ])[1 ])
36
36
@fastmath @simd for i in 1 : length (y)- 1
37
37
@inbounds retval += (x[i+ 1 ] - x[i]) * (y[i] + y[i+ 1 ])
38
38
end
39
39
return 0.5 * retval
40
40
end
41
41
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 )
43
43
retval = zero (promote (x[1 ], y[1 ])[1 ])
44
44
N = length (y) - 1
45
45
@fastmath @simd for i in 2 : N
@@ -48,7 +48,7 @@ function integrate{X<:Real, Y<:Real}(x::AbstractVector{X}, y::AbstractVector{Y},
48
48
@inbounds return (x[end ] - x[1 ]) / N * (retval + 0.5 * y[1 ] + 0.5 * y[end ])
49
49
end
50
50
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 )
52
52
@assert length (x) == length (y) " x and y vectors must be of the same length!"
53
53
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
54
54
for i in 5 : length (y) - 1
@@ -57,7 +57,7 @@ function integrate{X<:Real, Y<:Real}(x::AbstractVector{X}, y::AbstractVector{Y},
57
57
return (x[end ] - x[1 ]) / (length (y) - 1 ) * retval
58
58
end
59
59
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 )
61
61
@inbounds retval = 17 * y[1 ] + 59 * y[2 ] + 43 * y[3 ] + 49 * y[4 ]
62
62
@inbounds retval += 49 * y[end - 3 ] + 43 * y[end - 2 ] + 59 * y[end - 1 ] + 17 * y[end ]
63
63
retval /= 48
@@ -67,6 +67,6 @@ function integrate{X<:Real, Y<:Real}(x::AbstractVector{X}, y::AbstractVector{Y},
67
67
@inbounds return (x[end ] - x[1 ]) / (length (y) - 1 ) * retval
68
68
end
69
69
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 ())
71
71
72
72
end
0 commit comments