lagrange_poly Function

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

Interpolates a Lagrange polynomial defined by n equidistant points between 0 and 1

Arguments

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

Return Value real(kind=wp), (n)


Called by

proc~~lagrange_poly~~CalledByGraph proc~lagrange_poly lagrange_poly proc~lagrange lagrange proc~lagrange->proc~lagrange_poly proc~test_009 test_009 proc~test_009->proc~lagrange_poly proc~test_010 test_010 proc~test_010->proc~lagrange_poly proc~test_011 test_011 proc~test_011->proc~lagrange_poly proc~test_012 test_012 proc~test_012->proc~lagrange_poly proc~test_013 test_013 proc~test_013->proc~lagrange_poly proc~test_014 test_014 proc~test_014->proc~lagrange_poly proc~create_lagrange Colormap%create_lagrange proc~create_lagrange->proc~lagrange proc~test_022 test_022 proc~test_022->proc~lagrange proc~test_023 test_023 proc~test_023->proc~lagrange proc~test_024 test_024 proc~test_024->proc~lagrange proc~test_025 test_025 proc~test_025->proc~lagrange proc~test_026 test_026 proc~test_026->proc~lagrange proc~test_032 test_032 proc~test_032->proc~lagrange proc~test_033 test_033 proc~test_033->proc~lagrange program~check check program~check->proc~test_009 program~check->proc~test_010 program~check->proc~test_011 program~check->proc~test_012 program~check->proc~test_013 program~check->proc~test_014 program~check->proc~test_022 program~check->proc~test_023 program~check->proc~test_024 program~check->proc~test_025 program~check->proc~test_026 program~check->proc~test_032 program~check->proc~test_033 proc~test_046 test_046 program~check->proc~test_046 proc~test_071 test_071 program~check->proc~test_071 proc~test_081 test_081 program~check->proc~test_081 proc~test_084 test_084 program~check->proc~test_084 proc~test_046->proc~create_lagrange proc~test_071->proc~create_lagrange proc~test_081->proc~create_lagrange proc~test_084->proc~create_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
        real(wp) :: B(n)
        integer :: i, l
        real(wp) :: inv, xi, xl

        if (n <= 1) error stop "Error: Number of points n must be greater than 1 in lagrange_poly."
        if (t < 0.0_wp .or. t > 1.0_wp) error stop "Error: t must be in [0,1] in lagrange_poly."
        B = 1.0_wp
        inv = 1.0_wp/real(n-1, wp)
        do i = 1, n
            xi = real(i-1, wp) * inv
            do l = 1, n
                if (l /= i) then
                    xl = real(l-1, wp) * inv
                    if (abs(xi-xl) >= tiny(0.0_wp)) then
                        B(i) = B(i)*(t-xl)/(xi-xl)
                    end if
                end if
            end do
        end do
    end function lagrange_poly