Numerical integration: quadgk vs integral

조회 수: 40 (최근 30일)
Mariano
Mariano 2015년 3월 6일
답변: Mariano 2019년 7월 3일
Hello: I have not been able to find out what is the underlying quadrature formula in Matlab's builtin function integral. I think that quad uses Simpson, quadl a Gauss-Lobato formula and quadgk the Gauss-Kronrod formula G7K15, and all of them use some kind of adaptative scheme. What does integral(f,a,b) do with my poor function f? When should I use integral and when quadgk? Thank you, Mariano

채택된 답변

Christiaan
Christiaan 2015년 3월 9일
편집: Christiaan 2015년 3월 9일
Dear Mariano,
The Mathlab function 'integral(fun,xmin,xmax)' numerically integrates function fun from xmin to xmax using global adaptive quadrature and default error tolerances.
In the documention of this function (doc integral), this ref can be found:
% Portions based on "quadva" by Lawrence F. Shampine.
% Ref: L.F. Shampine, "Vectorized Adaptive Quadrature in Matlab",
% Journal of Computational and Applied Mathematics 211, 2008, pp.131-140
In the Documentation of quadgk you can find a list of multiple quadrature functions that can be used whith there (dis)advantages.
Kind regards, Christiaan
  댓글 수: 4
TheStranger
TheStranger 2017년 9월 3일
Strange, I tried both of them on some pretty complicated function and the answers differ by ~10^(-8) Also, for some strange reason, integral does not have an option "MaxIntervalCount", while quadgk does.
Josh Meyer
Josh Meyer 2019년 7월 2일
To summarize the differences between the two functions:
  • integral and quadgk use the same quadrature method as described in the reference paper
  • integral and quadgk use different default error tolerances for RelTol and AbsTol
  • quadgk has the MaxIntervalCount option, and uses a relatively small default value compared to integral. This means that with integral you will rarely if ever need to adjust this parameter (hence why it isn't there). This would only be with highly oscillatory integrands that are difficult to evaluate.
  • quadgk has an extra output that approxmates the absolute error. This lets you specify MaxIntervalCount, check the error in the calculation, and adjust MaxIntervalCount as needed.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Mariano
Mariano 2019년 7월 3일
Thanks a lot for your answers. They have been very helpful.
Best wishes,
Mariano

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by