File Exchange

image thumbnail

Array numerical integration by enhanced midpoint rule

version 1.0.5 (179 KB) by Sanjar Abrarov
Program performs accurate computation of proper integrals with arrays for the lower and upper bounds.

4 Downloads

Updated 17 Apr 2019

View License

This function file computes proper integrals over interval [a,b] by enhanced midpoint integration method based on a generalization of the conventional midpoint rule. In contrast to the existing Matlab built-in functions for numerical integration, this program can be used with arrays for the upper and lower integration limits. Such an approach can save significantly computational time. Accuracy in this numerical integration is controlled by truncating integers M and N. The derivation and implementation of the numerical integration formula are shown in works [1, 2]. Some additional information can be found in the supplementary readme.pdf file.

REFERENCES
[1] S. M. Abrarov and B. M. Quine, A formula for pi involving nested radicals, Ramanujan J. 46 (3) (2018) 657-665. https://doi.org/10.1007/s11139-018-9996-8

[2] S. M. Abrarov and B. M. Quine, Identities for the arctangent function by enhanced midpoint integration and the high-accuracy computation of pi, arXiv:1604.03752 (2016). https://arxiv.org/abs/1604.03752

Cite As

Sanjar Abrarov (2019). Array numerical integration by enhanced midpoint rule (https://www.mathworks.com/matlabcentral/fileexchange/71037-array-numerical-integration-by-enhanced-midpoint-rule), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (3)

This formula for numerical integration is a generalization of the conventional midpoint rule. However, it is called 'enhanced midpoint rule' since the terminologies like 'generalized midpoint rule' or 'generalization of midpoint rule' are already used for entirely different methods of integration.

The image shows the integration formula we used in this Matlab code. Double click the image to see it in a higher resolution.

Currently, Matlab built-in functions do not support arrays a and b for the lower and upper bounds in numerical integration. Therefore, we have to nest the computational flow if we want to compute an integral for many values of a and b:

x = sym('x');
a = linspace(-6,0,1e4); % lower bounds
b = linspace(0,6,1e4); % upper bounds
tic; for n=1:1e4; double(int(exp(-x^2)*sin(x)/x,[a(n),b(n)])); end; toc

However, this way of computation will take a lot of time. The proposed function file can be efficient to accelerate computation. For example, we can use the following command lines without nesting:

a = linspace(-6,0,1e4); % lower bounds
b = linspace(0,6,1e4); % upper bounds
tic; NInt = numint('exp(-x^2)*sin(x)/x',a,b,10,10); toc

Application without nesting makes computation faster by several orders of the magnitude.

Updates

1.0.5

Image frame is adjusted.

1.0.4

Image is changed.

1.0.3

Minor corrections in comments.

1.0.2

Some comments are corrected.

1.0.1

The code is simplified.

MATLAB Release Compatibility
Created with R2014a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Discover Live Editor

Create scripts with code, output, and formatted text in a single executable document.


Learn About Live Editor