Conversation
|
I managed to implement the first 4 closed Newton-Cotes formulas in 1 function, just distinguished by 1 parameter. |
|
pinging potential reviewers @christiankral @casella @HansOlsson @henrikt-ma @maltelenz @MartinOtter |
|
@HansOlsson to explain the motivation to implement rather simple quadrature formulas: |
|
Looking at the code and at: https://www.researchgate.net/publication/226706221_Adaptive_Quadrature-Revisited (which should replace the ftp-link) my only reaction is that the code is stupid and stupidly obscure. Without looking further: Do you see and understand the stopping criteria for the recursion, and how it relates to tolerance? The correct answer is: There are a number of issues with that:
|
|
@HansOlsson no I don't understand the code, and I don't trust it. |
As far as I understand the code implements the algorithm from the paper, it's just that the paper is more trying to be clever than correct and robust; so the problem isn't so much the Modelica-implementation as the underlying paper (although there are at least two issues with the Modelica implementation - related to the convergence criteria). Looking more at this and the paper contents:
I have tried to patch it as follows: |
HansOlsson
left a comment
There was a problem hiding this comment.
I agree that the original adaptive quadratureLobatto wasn't working - and needs to be updated; see separate PR.
However, a non-adaptive Newton-Cotes as this one seems like a step backwards, so:
- It may be a necessary step backwards
- Making it adaptive seem possible, but might run into the same issues and clearly take a lot of time to get right
- A compromise might be to add an optional output for an error estimate
- Clearly state that it is non-adaptive and highlight the benefits of a non-adaptive algorithm, e.g., that the result is differentiable
The last option may be the best.
Co-authored-by: Hans Olsson <HansOlsson@users.noreply.github.com>
Co-authored-by: Hans Olsson <HansOlsson@users.noreply.github.com>
HansOlsson
left a comment
There was a problem hiding this comment.
Looks ok, but might better document that it is non-adaptive which gives differentiable results.
|
@HansOlsson differentiable with respect to what? fun? a and b? Error term: Good idea but rather hard to compute, you need a higher derivative of the integrand (taken from Wikipedia): So the only thing that remains is to state that the formulas are non-adaptive but "composite" fomrulations, |

When investigating the relation between spatial flux density distribution of a rotating rotor (with permanent magnets) and the flux linkage of a coil in the stator core (to calculate the induce voltage), I have to calculate an integral over the angle spanned by the coil. Since quadratureLobatto has some problems with a moving integration interval, I implemented two less sophisticated quadrature functions: quadratureTrapezoidal (based on the trapezoidal rule) and quadratureSimpson (based on Simpson's rule).
Both are tested in the example MovingIntegral (using the utility function funB). That's also a nice example for the usage of quadrature functions. Defined comparison signals, no backwards compatibility issues.