Specifying step widths for numerical integration in MATLAB

657 Views Asked by At

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:

  1. How can I specify the maximum step width (and the amount of summation points) for the sum? As far as I understand integral calculates this to get a specific accuracy that can also be set using AbsTol, 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.
  2. When specifying and increasing the accuracy using AbsTol the 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 the integral (or similar) algorithm to output a vector of these summation points – how can this be done?
  3. Which integration algorithm works with non-equidistant step widths?

Please let me know if something is not clear.

1

There are 1 best solutions below

1
On BEST ANSWER

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 integral or quadgk. I would actually advise against it, you should rather set a maximal number of subdivisions. If you open ./private/integralCalc/ from integral file position, you will see the inner workings of the integration. The original [a,b] interval is split into INITIALINTERVALCOUNT subintervals (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 called MAXINTERVALCOUNT that sets the maximal number of subdivisions. Since the integral function 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 of quadgk, you can directly set the maximum number of intervals in the option structure.

2

Assuming that you're interested in integral you should look into the subs variable of the iterateScalarValued and iterateArrayValued functions of integralCalc or the subs variable of quadgk. There is a line where some parts of subs are 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 integral and quadgk use 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.