1
1
using DataInterpolations
2
2
using DataInterpolations: integral, derivative, invert_integral
3
- using FiniteDifferences
4
3
5
4
function test_integral_inverses (method; args = [], kwargs = [])
6
5
A = method (args... ; kwargs... , extrapolation = ExtrapolationType. Extension)
@@ -21,6 +20,21 @@ function test_integral_inverses(method; args = [], kwargs = [])
21
20
@test @inferred (A (ts[37 ])) == A (ts[37 ])
22
21
end
23
22
23
+ function test_integral_inverse_extrapolation ()
24
+ # Linear function with constant extrapolation
25
+ t = collect (0 : 4 )
26
+ u = [0.0 , 2.0 , 3.0 , 4.0 ]
27
+ A = LinearInterpolation (u, t, extrapolation = ExtrapolationType. Constant)
28
+
29
+ A_intinv = invert_integral (A, extrapolation_left = ExtrapolationType. Extension,
30
+ extrapolation_right = ExtrapolationType. Extension)
31
+
32
+ # for a linear function, the integral is quadratic
33
+ # but the constant extrapolation part is linear.
34
+ A_5 = 1 / 2 * 4.0 ^ 2 + 5.0
35
+ @test A_int_inv (A_5) ≈ 5.0
36
+ end
37
+
24
38
@testset " Linear Interpolation" begin
25
39
t = collect (1 : 5 )
26
40
u = [1.0 , 1.0 , 2.0 , 4.0 , 3.0 ]
29
43
u = [1.0 , - 1.0 , 2.0 , 4.0 , 3.0 ]
30
44
A = LinearInterpolation (u, t)
31
45
@test_throws DataInterpolations. IntegralNotInvertibleError invert_integral (A)
46
+
47
+ test_integral_inverse_extrapolation ()
32
48
end
33
49
34
50
@testset " Constant Interpolation" begin
0 commit comments