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

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

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.
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)

Categories

Find more on Numerical Integration and Differential Equations in Help Center and File Exchange

Asked:

on 28 Nov 2014

Edited:

on 21 Dec 2014

Community Treasure Hunt

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

Start Hunting!