Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The precision of gausslegendre can be improved #126

Open
hyrodium opened this issue Sep 14, 2023 · 1 comment
Open

The precision of gausslegendre can be improved #126

hyrodium opened this issue Sep 14, 2023 · 1 comment

Comments

@hyrodium
Copy link
Collaborator

hyrodium commented Sep 14, 2023

MWE:

julia> using FastGaussQuadrature, LinearAlgebra, Plots

julia> errors = Float64[]
Float64[]

julia> for n in 6:100
           nodes, weights = gausslegendre(n)
           push!(errors, norm([dot(weights, nodes.^p) - 2/(1+p) for p in 2:2:10], Inf))
       end

julia> plot(6:100, errors)

gausslegendre

The precision with $n\le60$ is worse than with $n>60$, and FastGaussQuadrature.rec can be improved.

elseif n 60
# NEWTON'S METHOD WITH THREE-TERM RECURRENCE:
return rec(n)
else
# USE ASYMPTOTIC EXPANSIONS:
return asy(n)
end

@hyrodium
Copy link
Collaborator Author

At least, it seems that the threshold 60 can be replaced with 40.

julia> using FastGaussQuadrature, LinearAlgebra, Plots

julia> errors = Float64[]
Float64[]

julia> for n in 6:100
           nodes, weights = gausslegendre(n)
           push!(errors, norm([dot(weights, nodes.^p) - 2/(1+p) for p in 2:2:10], Inf))
       end

julia> plot(6:100, errors)

julia> errors_asy = Float64[]
Float64[]

julia> for n in 6:100
           nodes, weights = FastGaussQuadrature.asy(n)
           push!(errors_asy, norm([dot(weights, nodes.^p) - 2/(1+p) for p in 2:2:10], Inf))
       end

julia> plot!(6:100, errors_asy, ylims=(0, 2e-15))

gausslegendre2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant