Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=wp), | intent(in) | :: | t | |||
integer, | intent(in) | :: | n |
order + 1 |
pure function lagrange_poly(t, n) result(B) real(wp), intent(in) :: t integer, intent(in) :: n !! order + 1 real(wp), allocatable :: B(:) integer :: i, l real(wp), dimension(:), allocatable :: Xth ! Create an array of n equidistant points between 0 and 1 allocate(Xth(n), source = 0.0_wp) do i = 1, n - 1 Xth(i) = 0.0_wp + real(i - 1, wp) * (1.0_wp - (0.0_wp)) / real(n - 1, wp) end do Xth(n) = 1.0_wp allocate(B(n), source = 1.0_wp) l = 0 i = 0 do i = 1, n do l = 1, n if (l /= i) then if (abs(Xth(i) - Xth(l)) >= tiny(0.0_wp)) then B(i) = B(i)*(t - Xth(l))/(Xth(i) - Xth(l)) end if end if end do end do end function lagrange_poly