### gausslegendre example Source: https://juliaapproximation.github.io/FastGaussQuadrature.jl/stable/gaussquadrature Example usage of gausslegendre to integrate x^4 over [-1,1]. The result is approximately 2/5, verified with the ≈ operator. ```julia julia> x, w = gausslegendre(3); julia> f(x) = x^4; julia> I = dot(w, f.(x)); julia> I ≈ 2/5 true ``` -------------------------------- ### Example: compute and verify Bessel roots Source: https://juliaapproximation.github.io/FastGaussQuadrature.jl/stable/besselroots Example usage of approx_besselroots to compute the first 10 roots for ν = 0.3 and verify that besselj evaluated at those roots is below 1e-12. ```julia julia> ν = 0.3; julia> roots = approx_besselroots(ν, 10); julia> zeros = (x -> besselj(ν, x)).(roots); julia> all(zeros .< 1e-12) true ``` -------------------------------- ### Example: integrate x^4 using gausslobatto Source: https://juliaapproximation.github.io/FastGaussQuadrature.jl/stable/gaussquadrature Computes the integral of f(x)=x^4 over [-1,1] using Gauss-Lobatto quadrature with 4 nodes and verifies the result equals 2/5. ```julia julia> x, w = gausslobatto(4); julia> f(x) = x^4; julia> I = dot(w, f.(x)); julia> I ≈ 2/5 true ``` -------------------------------- ### Example: gausslaguerre(3) integration of x^4 Source: https://juliaapproximation.github.io/FastGaussQuadrature.jl/stable/gaussquadrature Example usage of gausslaguerre(3) to approximate the integral of x^4 with weight e^{-x}. The result is approximately 24. ```julia julia> x, w = gausslaguerre(3); julia> f(x) = x^4; julia> I = dot(w, f.(x)); julia> I ≈ 24 true ``` -------------------------------- ### Example: gausslaguerre(3, 1.0) integration of x^4 Source: https://juliaapproximation.github.io/FastGaussQuadrature.jl/stable/gaussquadrature Example usage of gausslaguerre(3, 1.0) to approximate the integral of x^4 with weight x e^{-x}. The result is approximately 120. ```julia julia> x, w = gausslaguerre(3, 1.0); julia> f(x) = x^4; julia> I = dot(w, f.(x)); julia> I ≈ 120 true ``` -------------------------------- ### gausshermite example Source: https://juliaapproximation.github.io/FastGaussQuadrature.jl/stable/gaussquadrature Example usage of gausshermite to integrate x^4 with weight exp(-x^2). The result is approximately 3√π/4, verified with the ≈ operator. ```julia julia> x, w = gausshermite(3); julia> f(x) = x^4; julia> I = dot(w, f.(x)); julia> I ≈ 3(√π)/4 true ``` -------------------------------- ### Example: endpoints are fixed at -1 and 1 Source: https://juliaapproximation.github.io/FastGaussQuadrature.jl/stable/gaussquadrature Shows that the first and last nodes from gausslobatto(4) are exactly -1.0 and 1.0. ```julia julia> x, w = gausslobatto(4); julia> x[1], x[end] (-1.0, 1.0) ``` -------------------------------- ### Compute Gauss-Legendre quadrature and check an integral Source: https://juliaapproximation.github.io/FastGaussQuadrature.jl/stable Uses gausslegendre(3) to obtain nodes and weights, then evaluates f(x) = x^4 and computes the dot product to approximate the integral from -1 to 1. The result is compared to 2/5, showing a numerical approximation. ```julia julia> using FastGaussQuadrature, LinearAlgebra julia> x, w = gausslegendre(3)([-0.7745966692414834, 0.0, 0.7745966692414834], [0.5555555555555556, 0.8888888888888888, 0.5555555555555556]) julia> f(x) = x^4f (generic function with 1 method) julia> I = dot(w, f.(x))0.4000000000000001 julia> I ≈ 2/5true ``` -------------------------------- ### approx_besselroots(ν::Real, n::Integer) Source: https://juliaapproximation.github.io/FastGaussQuadrature.jl/stable/besselroots Documentation for the approx_besselroots function, which computes the first n roots of the Bessel function J_ν(x). ```APIDOC ## approx_besselroots(ν::Real, n::Integer) -> Vector{Float64} ### Description Return the first n roots of the Bessel function J_ν(x). Note that this function is only 12-digits of precision. ### Method Function call ### Endpoint `FastGaussQuadrature.approx_besselroots(ν::Real, n::Integer)` ### Parameters - **ν** (Real) - Required - The order of the Bessel function. - **n** (Integer) - Required - The number of roots to return. ### Returns - **Vector{Float64}** - The first n roots of the Bessel function. ### Example ```julia julia> ν = 0.3; julia> roots = approx_besselroots(ν, 10); julia> zeros = (x -> besselj(ν, x)).(roots); julia> all(zeros .< 1e-12) true ``` ``` -------------------------------- ### gausslegendre(n::Integer) -> x, w Source: https://juliaapproximation.github.io/FastGaussQuadrature.jl/stable/gaussquadrature Computes the nodes and weights for Gauss-Legendre quadrature on the interval [-1, 1] with weight function w(x)=1. Uses analytic expressions for n≤5, Newton's method for n≤60, and asymptotic expansions for n>60. ```APIDOC ## gausslegendre(n::Integer) -> x, w ### Description Return nodes `x` and weights `w` of Gauss-Legendre quadrature. ### Method Function call ### Endpoint `gausslegendre(n::Integer)` ### Parameters - **n** (Integer) - Required - Number of quadrature nodes. ### Returns - **x** (Vector) - Nodes of the quadrature rule. - **w** (Vector) - Weights of the quadrature rule. ### Example ```julia julia> x, w = gausslegendre(3); julia> f(x) = x^4; julia> I = dot(w, f.(x)); julia> I ≈ 2/5 true ``` ``` -------------------------------- ### gausslobatto(n::Integer) -> x, w Source: https://juliaapproximation.github.io/FastGaussQuadrature.jl/stable/gaussquadrature Computes the nodes x and weights w for Gauss-Lobatto quadrature with n points. The nodes include the endpoints -1 and 1. ```APIDOC ## gausslobatto(n::Integer) -> x, w ### Description Return nodes `x` and weights `w` of Gauss-Lobatto quadrature. The quadrature rule approximates the integral of f(x) from -1 to 1 as a weighted sum of f evaluated at the nodes. ### Method Function call ### Endpoint `gausslobatto(n::Integer)` ### Parameters - **n** (Integer) - Required - The number of quadrature nodes and weights to compute. ### Returns - **x** (Vector) - The nodes of the quadrature, with the first and last elements fixed at -1 and 1. - **w** (Vector) - The corresponding weights. ### Examples julia julia> x, w = gausslobatto(4); julia> f(x) = x^4; julia> I = dot(w, f.(x)); julia> I ≈ 2/5 true Note that the both ends of nodes are fixed at -1 and 1. julia julia> x, w = gausslobatto(4); julia> x[1], x[end] (-1.0, 1.0) ``` -------------------------------- ### Benchmark gausslegendre with 1000000001 nodes Source: https://juliaapproximation.github.io/FastGaussQuadrature.jl/stable/benchmark Benchmarks gausslegendre with one billion plus one nodes, as done in the referenced paper. The output shows the computation takes about 23 seconds and allocates 22.35 GiB. Note that nodes near the endpoints coalesce in 16-digit precision. ```julia julia> @btime gausslegendre(1000000001); 23.363 s (10 allocations: 22.35 GiB) ``` -------------------------------- ### gausslegendre method signature Source: https://juliaapproximation.github.io/FastGaussQuadrature.jl/stable/gaussquadrature Method signature for computing Gauss-Legendre nodes and weights. Use for n≤5 with analytic expressions, n≤60 with Newton's method, and n>60 with asymptotic expansions. ```julia gausslegendre(n::Integer) -> x, w # nodes, weights ``` -------------------------------- ### approx_besselroots method signature Source: https://juliaapproximation.github.io/FastGaussQuadrature.jl/stable/besselroots Method signature for approx_besselroots, which returns the first n roots of the Bessel function with 12 digits of precision. ```julia approx_besselroots(ν::Real, n::Integer) -> Vector{Float64} ``` -------------------------------- ### gausshermite(n::Integer; normalize = false) -> x, w Source: https://juliaapproximation.github.io/FastGaussQuadrature.jl/stable/gaussquadrature Computes the nodes and weights for Gauss-Hermite quadrature on the real line with weight function exp(-x^2). Optionally normalizes to use the standard normal density. Uses Newton's method with recurrence or asymptotic expansions depending on n. ```APIDOC ## gausshermite(n::Integer; normalize = false) -> x, w ### Description Return nodes `x` and weights `w` of Gauss-Hermite quadrature. ### Method Function call ### Endpoint `gausshermite(n::Integer; normalize = false)` ### Parameters - **n** (Integer) - Required - Number of quadrature nodes. - **normalize** (Bool) - Optional - If `true`, computes quadrature for the standard normal density function instead of exp(-x^2). Default is `false`. ### Returns - **x** (Vector) - Nodes of the quadrature rule. - **w** (Vector) - Weights of the quadrature rule. ### Example ```julia julia> x, w = gausshermite(3); julia> f(x) = x^4; julia> I = dot(w, f.(x)); julia> I ≈ 3(√π)/4 true ``` ``` -------------------------------- ### Benchmark all Gauss rules with 100000 nodes Source: https://juliaapproximation.github.io/FastGaussQuadrature.jl/stable/benchmark Benchmarks the computation of 100000 nodes and weights for each Gauss rule in FastGaussQuadrature.jl using @btime. The output shows the time and allocations for each rule, with gausschebyshev being the fastest and gaussjacobi the slowest. ```julia julia> using LinearAlgebra, BenchmarkTools, FastGaussQuadrature julia> @btime gausschebyshev(100000); 743.568 μs (4 allocations: 1.53 MiB) julia> @btime gausslegendre(100000); 1.884 ms (10 allocations: 2.62 MiB) julia> @btime gaussjacobi(100000, 0.9, -0.1); 538.739 ms (5374 allocations: 1.26 GiB) julia> @btime gaussradau(100000); 531.302 ms (703555 allocations: 1.27 GiB) julia> @btime gausslobatto(100000); 534.783 ms (3881 allocations: 1.26 GiB) julia> @btime gausslaguerre(100000); 83.107 ms (10008 allocations: 2.44 MiB) julia> @btime gausshermite(100000); 140.131 ms (200718 allocations: 126.28 MiB) ``` -------------------------------- ### gausslaguerre(n) method signature Source: https://juliaapproximation.github.io/FastGaussQuadrature.jl/stable/gaussquadrature Method signature for Gauss-Laguerre quadrature with default weight function. Returns nodes x and weights w. ```julia gausslaguerre(n::Integer) -> x, w # nodes, weights ``` -------------------------------- ### gausslaguerre(n, α) method signature Source: https://juliaapproximation.github.io/FastGaussQuadrature.jl/stable/gaussquadrature Method signature for generalized Gauss-Laguerre quadrature with weight x^α e^{-x}. Returns nodes x and weights w. ```julia gausslaguerre(n::Integer, α::Real) -> x, w # nodes, weights ``` -------------------------------- ### Verify BESSELJ1_ON_BESSELJ0_ROOTS values Source: https://juliaapproximation.github.io/FastGaussQuadrature.jl/stable/misc Verifies that `FastGaussQuadrature.BESSELJ1_ON_BESSELJ0_ROOTS` contains the values of Bessel function J1 evaluated on the first ten roots of J0, by comparing the squared values from `approx_besselroots(0,10)` with the stored constant. ```julia julia> roots = approx_besselroots(0,10); julia> (besselj1.(roots)).^2 ≈ FastGaussQuadrature.BESSELJ1_ON_BESSELJ0_ROOTS true ``` -------------------------------- ### gausshermite method signature Source: https://juliaapproximation.github.io/FastGaussQuadrature.jl/stable/gaussquadrature Method signature for computing Gauss-Hermite nodes and weights. Use for n<200 with three-term recurrence, and for n≥200 with uniform asymptotic expansion. The normalize=true option computes integrals with the standard normal density. ```julia gausshermite(n::Integer; normalize = false) -> x, w # nodes, weights ``` -------------------------------- ### gausslaguerre(n::Integer) Source: https://juliaapproximation.github.io/FastGaussQuadrature.jl/stable/gaussquadrature Computes nodes and weights for Gauss-Laguerre quadrature with weight exp(-x) on [0, ∞). ```APIDOC ## gausslaguerre(n::Integer) ### Description Return nodes `x` and weights `w` of Gauss-Laguerre quadrature for the weight function w(x)=exp(-x) on [0, +∞). ### Method Function call ### Endpoint `gausslaguerre(n::Integer) -> x, w` ### Parameters #### Arguments - **n** (Integer) - Required - Number of quadrature nodes. ### Returns - **x** (Vector) - Nodes of the quadrature rule. - **w** (Vector) - Weights of the quadrature rule. ### Example ```julia julia> x, w = gausslaguerre(3); julia> f(x) = x^4; julia> I = dot(w, f.(x)); julia> I ≈ 24 true ``` ``` -------------------------------- ### gausslobatto function signature Source: https://juliaapproximation.github.io/FastGaussQuadrature.jl/stable/gaussquadrature Method signature for gausslobatto, which returns nodes x and weights w for Gauss-Lobatto quadrature. ```julia gausslobatto(n::Integer) -> x, w # nodes, weights ``` -------------------------------- ### gausslaguerre(n::Integer, α::Real) Source: https://juliaapproximation.github.io/FastGaussQuadrature.jl/stable/gaussquadrature Computes nodes and weights for generalized Gauss-Laguerre quadrature with weight x^α exp(-x) on [0, ∞). ```APIDOC ## gausslaguerre(n::Integer, α::Real) ### Description Return nodes `x` and weights `w` of generalized Gauss-Laguerre quadrature for the weight function w(x)=x^α exp(-x) on [0, +∞). ### Method Function call ### Endpoint `gausslaguerre(n::Integer, α::Real) -> x, w` ### Parameters #### Arguments - **n** (Integer) - Required - Number of quadrature nodes. - **α** (Real) - Required - Exponent in the weight function. ### Returns - **x** (Vector) - Nodes of the quadrature rule. - **w** (Vector) - Weights of the quadrature rule. ### Example ```julia julia> x, w = gausslaguerre(3, 1.0); julia> f(x) = x^4; julia> I = dot(w, f.(x)); julia> I ≈ 120 true ``` ``` -------------------------------- ### gausslaguerre_asy Source: https://juliaapproximation.github.io/FastGaussQuadrature.jl/stable/gaussquadrature Computes Gauss-Laguerre quadrature using asymptotic expansions. Can be manually invoked for custom accuracy. ```APIDOC ## gausslaguerre_asy ### Description Computes Gauss-Laguerre quadrature nodes and weights using asymptotic expansions. This routine can be manually invoked when the default algorithm does not achieve the desired accuracy. ### Method Function call ### Endpoint `gausslaguerre_asy` ### Parameters No parameters documented. ### Returns No return values documented. ``` -------------------------------- ### Verify BESSELJ0_ROOTS accuracy Source: https://juliaapproximation.github.io/FastGaussQuadrature.jl/stable/misc Checks that the first twenty roots of the Bessel function J0 stored in `FastGaussQuadrature.BESSELJ0_ROOTS` are accurate to within 1e-14 by evaluating `besselj0` at each root and confirming all values are below the tolerance. ```julia julia> zeros = besselj0.(FastGaussQuadrature.BESSELJ0_ROOTS); julia> all(zeros .< 1e-14) true ``` -------------------------------- ### Verify AIRY_ROOTS accuracy Source: https://juliaapproximation.github.io/FastGaussQuadrature.jl/stable/misc Verifies that the first 11 roots of the Airy function stored in `FastGaussQuadrature.AIRY_ROOTS` are accurate to within 1e-14 by evaluating the Airy function at each root and checking that all values are below the tolerance. ```julia julia> zeros = airy.(FastGaussQuadrature.AIRY_ROOTS); julia> all(zeros .< 1e-14) true ``` -------------------------------- ### gausslaguerre_GW Source: https://juliaapproximation.github.io/FastGaussQuadrature.jl/stable/gaussquadrature Computes Gauss-Laguerre quadrature using the Golub-Welsch algorithm. Can be manually invoked for custom accuracy. ```APIDOC ## gausslaguerre_GW ### Description Computes Gauss-Laguerre quadrature nodes and weights using the Golub-Welsch algorithm. This routine can be manually invoked when the default algorithm does not achieve the desired accuracy. ### Method Function call ### Endpoint `gausslaguerre_GW` ### Parameters No parameters documented. ### Returns No return values documented. ``` -------------------------------- ### gausslaguerre_rec Source: https://juliaapproximation.github.io/FastGaussQuadrature.jl/stable/gaussquadrature Computes Gauss-Laguerre quadrature using Newton iterations on the recurrence relation. Can be manually invoked for custom accuracy. ```APIDOC ## gausslaguerre_rec ### Description Computes Gauss-Laguerre quadrature nodes and weights using Newton iterations applied to evaluation using the recurrence relation. This routine can be manually invoked when the default algorithm does not achieve the desired accuracy. ### Method Function call ### Endpoint `gausslaguerre_rec` ### Parameters No parameters documented. ### Returns No return values documented. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.