Skip to content

Commit

Permalink
test zeros of a cubic spline
Browse files Browse the repository at this point in the history
  • Loading branch information
perazz committed Aug 6, 2023
1 parent 6f1ef5b commit b232d22
Showing 2 changed files with 26 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test/fitpack_curve_tests.f90
Original file line number Diff line number Diff line change
@@ -28,6 +28,7 @@ module fitpack_curve_tests
private

public :: test_sine_fit
public :: test_zeros
public :: test_periodic_fit
public :: test_parametric_fit
public :: test_closed_fit
@@ -459,6 +460,30 @@ logical function test_sine_fit() result(success)

end function test_sine_fit

! Test zeros of a cubic spline
logical function test_zeros() result(success)

type(fitpack_curve) :: curve
real(RKIND), allocatable :: x(:),y(:),x0(:)
integer :: ierr

success = .false.

! Try f(x) = x3 Ð 3x2 + 2x = x(x Ð 1)(x Ð 2), with real roots x = 0, x = 1, and x = 2.
x = linspace(-10.0_RKIND,10.0_RKIND,20)
y = x**3-3*x**2+2*x

! Get the interpolating curve
ierr = curve%new_fit(x,y,smoothing=zero)

! Get the zeros
x0 = curve%zeros(ierr)

success = FITPACK_SUCCESS(ierr) .and. size(x0)==3 &
.and. all(abs(x0(1:3)-[zero,one,two])<sqrt(epsilon(zero)))

end function test_zeros

! Periodic test: fit a cosine function
logical function test_periodic_fit() result(success)

1 change: 1 addition & 0 deletions test/test.f90
Original file line number Diff line number Diff line change
@@ -41,6 +41,7 @@ subroutine run_interface_tests()

! Sine function interpolant: test f(x) and df/dx
call add_test(test_sine_fit())
call add_test(test_zeros())
call add_test(test_periodic_fit())
call add_test(test_parametric_fit())
call add_test(test_closed_fit())

0 comments on commit b232d22

Please sign in to comment.