fix quadrature bug (increased error w/quad_pts)#2
Open
nestor98 wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi!
running some experiments (with the current version) I noticed that sometimes increasing quad_pts in
iad.Sample.rtmade the quadrature diverge and then settle on some different (wrong) value at higher quad_pts. I fixed the problem (with some help from an LLM...)The issue
An example small reproduction:
This prints:
Then, around 100 quad_pts it starts raising
ValueError: array must not contain infs or NaNsIssue 2
A related error happens with radau quadrature (also for higher quad_pts), which returns weights that do not add to one as they should:
gausssum(w)radausum(w)The fix
The problem is
pp = scipy.special.legendre(n - 1).deriv(1), where the deriv function evaluates the polynomial, which seems to be very ill conditioned in floating point for high degrees.The fix is to switch that derivative to an analytical version (Bonnet's) that doesn't have the numerical issue:
This has been patched in quadrature.py, also changing legendre for eval_legendre, which should evaluate faster (didn't actually measure this).
Results
Now the integration from issue 1 converges correctly:
T_LT_L