When numerically integrating a function using MATLAB's integral or quadgk one specifies the function with the input parameter x, the xmin and xmax. $$ \int_{xmin}^{xmax} f(x) dx$$
Numerically this should look like one of these sums:
$$1: \sum_{n=xmin}^{N=xmax} f(n)*s<n \\
2:\sum_{n=xmin}^{N=xmax} \omega_i f(n)<n
$$
where $s$ is a constant step width and $\omega_i$ is a weight for the Gaussian quadrature.
When using integral or quadgk I encountered some problems:
- How can I specify the maximum step width (and the amount of summation points) for the sum? As far as I understand
integralcalculates this to get a specific accuracy that can also be set usingAbsTol, RelTol, but for my function it doesn't work well, so I would like to test it by reducing the amount of the step width manually. - When specifying and increasing the accuracy using
AbsTolthe amount of summation points should probably also increase. So if I want an accuracy of $10^{-15}$ there should be more summation points then for an accuracy of $10^{-10}$. I would like theintegral(or similar) algorithm to output a vector of these summation points – how can this be done? - Which integration algorithm works with non-equidistant step widths?
Please let me know if something is not clear.
Your question is rather complicated to answer and mentions two different functions. In essence you want to specify a maximum evaluation time to the functions.
1
Using the supplied workings of MATLAB, you cannot supply the maximum step width to either
integralorquadgk. I would actually advise against it, you should rather set a maximal number of subdivisions. If you open./private/integralCalc/fromintegralfile position, you will see the inner workings of the integration. The original [a,b] interval is split intoINITIALINTERVALCOUNTsubintervals (set to 10 by./private/integralParseArgs) which can then be subdivided further based on local errors (this is an adaptive quadrature). There is a variable calledMAXINTERVALCOUNTthat sets the maximal number of subdivisions. Since theintegralfunction is able to integrate up to infinity it might be wiser to set a maximum number of intervals rather than a maximal step size. In the case ofquadgk, you can directly set the maximum number of intervals in the option structure.2
Assuming that you're interested in
integralyou should look into thesubsvariable of theiterateScalarValuedanditerateArrayValuedfunctions ofintegralCalcor thesubsvariable ofquadgk. There is a line where some parts ofsubsare removed (since they have sufficient precision), you could simply add the removed subintervals to some output variable.3
This part of the question does not really makes sense for adaptive integration. Both
integralandquadgkuse non constant stepsize due to division of subintervals to minimize errors, which is why you should set a maximum number of subdivisions rather than maximum step size.