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

Final definite-integral interface wrapping up all integral work!! (integrals #10) #129

Merged
merged 7 commits into from Oct 31, 2020

Conversation

sritchie
Copy link
Member

It's done!! This PR:

  • wraps up everything in this series behind a definite-integral function and interface
  • adds more tests flexing some of the new abilities of the library (most of the abilities are tested by the individual integrators, of course...)

@littleredcomputer, I realize I removed your adaptive simpson's implementation, which is great - wdyt, should we move that over to simpson.cljc, and make it its own integrator?

IT'S DONE!

;; more general method.

(def ^:private quadrature-methods
{:open {:method :adaptive-bulirsch-stoer
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we've dominated scipy :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That we have. I really think you have covered some uncharted territory. As an overview, it's clear that GJS wanted strong integrators capable of producing plots of function values with integrals on the RHS, looked at the state of the art, realized that the QUADPACK people had lost the plot, and decided to return to first principles with the Memo. But his approach was depth-first, since numerical analysis is not the focus of his work. This is different, these methods are quite a bit better than just cranking down $h$ and hoping for the best. The empirical measurement of the savings in function evaluations was worth measuring and the Achilles' heel of all the naive techniques...that eventually you will lose significance by subtracting nearly equal things when you lower $h$ too far...is really elegantly captured by all of this work.

;;
;; Here we are! The one function you need care about if you're interested in
;; definite integrals. Learn to use this, and then dig in to the details of
;; individual methods if you run inton trouble or want to learn more. Enjoy!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

intoninto

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@codecov-io
Copy link

Codecov Report

❗ No coverage uploaded for pull request base (sritchie/integral_9@609cf24). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@                  Coverage Diff                   @@
##             sritchie/integral_9     #129   +/-   ##
======================================================
  Coverage                       ?   85.95%           
======================================================
  Files                          ?       71           
  Lines                          ?     6080           
  Branches                       ?      297           
======================================================
  Hits                           ?     5226           
  Misses                         ?      557           
  Partials                       ?      297           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 609cf24...3e6e362. Read the comment docs.

Copy link
Collaborator

@littleredcomputer littleredcomputer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bravo! 🥇

;; more general method.

(def ^:private quadrature-methods
{:open {:method :adaptive-bulirsch-stoer
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That we have. I really think you have covered some uncharted territory. As an overview, it's clear that GJS wanted strong integrators capable of producing plots of function values with integrals on the RHS, looked at the state of the art, realized that the QUADPACK people had lost the plot, and decided to return to first principles with the Memo. But his approach was depth-first, since numerical analysis is not the focus of his work. This is different, these methods are quite a bit better than just cranking down $h$ and hoping for the best. The empirical measurement of the savings in function evaluations was worth measuring and the Achilles' heel of all the naive techniques...that eventually you will lose significance by subtracting nearly equal things when you lower $h$ too far...is really elegantly captured by all of this work.

(is (near 2.0532 (f 0.60)))
(is (near 2.08001 (f 0.75)))
(is (near 2.11368 (f 0.9))))))

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we getting more significance in the result of this just using straight-up integrate? This one is improper on the left, so by saying that in the options we should get much better results without asking for 1e-9.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's improper on the right, yeah? 0 gives us a denominator of 1 / sqrt(2g (1 - cos(a)), while a gives us a pole.

It looks like we can tighten up the near test and remove the options map, and get a passing test:

(testing "harder"
    (let [near (v/within 1e-5)
          g 9.8
          integrand (fn [theta0]
                      (fn [theta]
                        (/ (Math/sqrt
                            (* 2 g (- (Math/cos theta)
                                      (Math/cos theta0)))))))
          L (fn [a]
              (let [f (integrand a)]
                (* 4 (q/definite-integral f 0 a {:method :closed-open}))))]
      (is (near 2.00992 (L 0.15)))
      (is (near 2.01844 (L 0.30)))
      (is (near 2.03279 (L 0.45)))
      (is (near 2.0532 (L 0.60)))
      (is (near 2.08001 (L 0.75)))
      (is (near 2.11368 (L 0.9)))))

I need to stare at this more, since I've lost touch with the physics and can't remember what system we're describing :)

@sritchie sritchie merged commit 62225ab into sritchie/integral_9 Oct 31, 2020
sritchie added a commit that referenced this pull request Oct 31, 2020
@sritchie sritchie deleted the sritchie/integral_10 branch October 31, 2020 21:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants