MATLAB provides various options to perform integration of a function. Depending on the type of integration, you can use different MATLAB functions.
int()
function: This function allows you to find the integral of a symbolic expression. For example, to find the integral of sin(x)
use the following code:main.m19 chars3 lines
This will return -cos(x) + C
, where C
is the constant of integration.
integral()
function: This function allows you to find the numeric value of a definite integral. For example, to find the value of ∫<sup>1</sup><sub>0</sub> x^2
dx
use the following code:main.m41 chars3 lines
This will return the answer as 0.3333
.
dblquad()
function: This function allows you to find the double integral of a function. For example, to find the value of ∫<sup>2</sup><sub>1</sub> ∫<sup>4</sup><sub>3</sub> (x+y)^2
dxdy
use the following code:main.m52 chars3 lines
This will return the answer as 270.0000
.
There are other functions available as well, depending on the type of integration required. You can use the help
command to learn more about the various functions.
gistlibby LogSnag