Returns a set of slightly randomized equally-spaced points that divide an interval.
for num_points
= 3:
o---|---|---|---o
1 2 3
returns: [0.25308641972530865, 0.5061728394506173, 0.759259259175926]
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | num_points |
the number of points in the interval |
the resultant vector
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