How do I get the number of iterations when using the quad(..) function.

3 views (last 30 days)
I am inputing on the Command Window:
[q, nfun]=quad(@(x) 1/pi*cos(sin(x)), 0,pi)
nfun seems to give me the number of evaluations for the answer q, but what I need is q for 5 iterations of the gauss quadrature method.
  2 Comments
Mike Hosea
Mike Hosea on 16 Dec 2014
Edited: Mike Hosea on 21 Dec 2014
I don't know what you mean by "iterations". Adaptive quadrature can be implemented recursively or iteratively. If it is implemented iteratively, it can be vectorized across all subintervals that currently need refinement, or it can handle each interval one at a time. The concept "5 iterations" doesn't make any sense for QUAD, which happens to be implemented using recursion.
John D'Errico
John D'Errico on 21 Dec 2014
Edited: John D'Errico on 21 Dec 2014
As well, quad does not use a gaussian quadrature method. You can't make quad use a method it is not programmed to employ. Nor is it really meaningful at all to talk about iterations of a locally adaptive method like quad. In some parts of the interval quad will go to more depth than others, so essentially more iterations. Thus iterations is simply not a meaningful concept for quad.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!