=QUADF(f, x, a, b, [options])
Use QUADF
to compute a proper or improper integral
using highly accurate adaptive algorithms.
With optional arguments, you can override the default integration algorithm as well as supply singular points for the integrand f(x) if applicable.
QUADF
can be nested to compute multiple integrals of any order.
f
a reference to the integrand formula.
If your integrand is too complex to represent by formulas, you can code it in a VBA function (see Example 6).
x
a reference to the variable of integration.
a
the integral lower limit.
b
the integral upper limit.
To input infinite limits use the string "INF" or "-INF" (case insensitive).
ctrl
a set of key/value pairs for algorithmic control as detailed below.
Description of key/value pairs for algorithmic control
Key | ALGOR |
Admissible Values (String) | QNG,QAG,QAGS,QK15,QK21,QK31,QK41,QK51,QK61 |
Default Value | QAG |
Remarks |
|
Keys | ATOL, RTOL |
Admissible Values (Real) | >= 0 |
Default Value | ATOL = 1.0E-7, RTOL = 1.0E-5 |
Remarks |
|
Key | MAXDIV |
Admissible Values (Integer) | >= 1 |
Default Value | 10000 |
Remarks | Not applicable for algorithm QNG or fixed-order QKn |
Key | GKPAIR |
Admissible Values (Integer) |
|
Default Value | 2 |
Remarks | Applicable only for algorithm QAG |
spts
list of known removable singular points for the integrand.
We define the integrand formula in A1 using X1 as variable. Excel reports the error #DIV/0! for the formula in A1 since X1 is undefined. This error can be ignored since X1 serves only as a dummy variable for the integrand function and its value is irrelevant for the integration computed in A2.
A | |
1 | =(2*X1^5-X1+3)/X1^2 |
2 | =QUADF(A1,X1,1,2) |
A | |
1 | #DIV/0! |
2 | 8.306852819 |
Note for ExceLab 365 users. Define any nonzero value for empty X1 to resolve initial #DIV/0! error in A1 or Excel will not execute dependent formula in A2. Not required for ExceLab 7 or Google Sheets Add-on
A | |
3 | =LN(X1)/SQRT(X1) |
4 | =QUADF(A3,X1,0,1,{"Algor","QAGS"}) |
A | |
3 | #NUM! |
4 | -4 |
Note for ExceLab 365 users. Define any positive value for empty X1 to resolve initial #NUM! error in A3 or Excel will not execute dependent formula in A4. Not required for ExceLab 7 or Google Sheets Add-on
The integrand in this example has two singularities at and . We make use of optional argument 6 to pass the singular points which are defined in vector B5:B6. Note that we skip over optional argument 5 since we do not alter any defaults.
A | B | |
5 | =ABS(X1-1/7)^(-1/4)*ABS(X1-2/3)^(-11/20) | =1/7 |
6 | =QUADF(A5,X1,0,1,,B5:B6) | =11/20 |
A | |
5 | 2.032940662 |
6 | 4.253687688 |
We could pass the singular points in argument 6 using constant array syntax {0.1428571, 0.55}, but we would lose some accuracy rounding 1/7.
A | |
7 | =1/(1+X1^2) |
8 | =QUADF(A7,X1,0,"inf") |
A | |
7 | 1 |
8 | 1.570796327 |
A | |
9 | =EXP(-X1*X1) |
10 | =QUADF(A9,X1,"-inf","inf") |
A | |
9 | 1 |
10 | 1.772453851 |
We demonstrate how to integrate a user defined VBA function with QUADF
.
You can define your own VBA functions in Excel which is quite powerful when your integrand is difficult to define with standard formulas. We will compute the integral
, where p is a constant parameter.
VBA is supported in ExceLab 7.0 only. ExceLab 365 which is based on cross-platform Office JS technology is not compatible with VBA
Insert a Module from the Insert Tab, then code the following function:
A | |
11 | =vbMyFunction(X1, 1) |
12 | =QUADF(A11,X1,1,2) |
A | |
11 | 0 |
12 | 0.909542505 |
Your VBA function name must be prefixed with "vb" to be used with ExceLab solvers.
X1 is just a dummy variable for the integrand function. Its value is ignored.
QUADF
algorithms are based on the numerical integration package QUADPACK. QUADF
default algorithm is QAG.
You can override the default algorithm in optional argument 5 with the key ALGOR For example: =QUADF(f, x, a, b, {"algor","qags"})
.