Interpolates a Lagrange polynomial defined by n equidistant points between 0 and 1
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=wp), | intent(in) | :: | t | |||
| integer, | intent(in) | :: | n |
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