lagrange_poly Function

private pure function lagrange_poly(t, n) result(B)

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: t
integer, intent(in) :: n

order + 1

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


Called by

proc~~lagrange_poly~~CalledByGraph proc~lagrange_poly lagrange_poly proc~lagrange lagrange proc~lagrange->proc~lagrange_poly proc~create_lagrange Colormap%create_lagrange proc~create_lagrange->proc~lagrange program~create create program~create->proc~create_lagrange

Source Code

    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