divide_interval Function

public function divide_interval(num_points) result(points)

Returns a set of slightly randomized equally-spaced points that divide an interval.

Example:

for num_points = 3:

     o---|---|---|---o
         1   2   3

returns: [0.25308641972530865, 0.5061728394506173, 0.759259259175926].

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: num_points

the number of points in the interval

Return Value real(kind=wp), dimension(:), allocatable

the resultant vector


Calls

proc~~divide_interval~~CallsGraph proc~divide_interval numdiff_utilities_module::divide_interval interface~unique numdiff_utilities_module::unique proc~divide_interval->interface~unique proc~unique_int numdiff_utilities_module::unique_int interface~unique->proc~unique_int proc~unique_real numdiff_utilities_module::unique_real interface~unique->proc~unique_real interface~expand_vector numdiff_utilities_module::expand_vector proc~unique_int->interface~expand_vector interface~sort_ascending numdiff_utilities_module::sort_ascending proc~unique_int->interface~sort_ascending proc~unique_real->interface~expand_vector proc~unique_real->interface~sort_ascending proc~expand_vector_int numdiff_utilities_module::expand_vector_int interface~expand_vector->proc~expand_vector_int proc~expand_vector_real numdiff_utilities_module::expand_vector_real interface~expand_vector->proc~expand_vector_real proc~sort_ascending_int numdiff_utilities_module::sort_ascending_int interface~sort_ascending->proc~sort_ascending_int proc~sort_ascending_real numdiff_utilities_module::sort_ascending_real interface~sort_ascending->proc~sort_ascending_real interface~swap numdiff_utilities_module::swap proc~sort_ascending_int->interface~swap proc~sort_ascending_real->interface~swap proc~swap_int numdiff_utilities_module::swap_int interface~swap->proc~swap_int proc~swap_real numdiff_utilities_module::swap_real interface~swap->proc~swap_real

Called by

proc~~divide_interval~~CalledByGraph proc~divide_interval numdiff_utilities_module::divide_interval proc~compute_sparsity_random_2 numerical_differentiation_module::compute_sparsity_random_2 proc~compute_sparsity_random_2->proc~divide_interval

Source Code

    function divide_interval(num_points) result(points)

    implicit none

    integer,intent(in)                :: num_points  !! the number of points in the interval
    real(wp),dimension(:),allocatable :: points      !! the resultant vector

    real(wp),parameter :: noise = 1.012345678901234567_wp !! a noise value. Not a round number
                                                          !! so as to avoid freak zeros in the
                                                          !! jacobian
    real(wp),parameter :: min_val = 10.0_wp * epsilon(1.0_wp) !! the minimize distance from the lower bound
    real(wp),parameter :: max_val = 1.0_wp - min_val          !! the minimize distance from the upper bound

    integer :: i !! counter
    real(wp) :: delta !! step size
    real(wp),dimension(:),allocatable :: tmp !! a temp array to hold the values

    delta = 1.0_wp / (num_points + 1)

    allocate(tmp(num_points))
    do i = 1, num_points
        tmp(i) = min(max(min_val,delta*i*noise),max_val)
    end do
    ! this is to protect for the min/max case if there
    ! are enough points so that some are duplicated near
    ! the bounds:
    points = unique(tmp,chunk_size=10)

    end function divide_interval