integrals in matlab

MATLAB provides various options to perform integration of a function. Depending on the type of integration, you can use different MATLAB functions.

  1. Symbolic Integration using 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.m
syms x
int(sin(x))
19 chars
3 lines

This will return -cos(x) + C, where C is the constant of integration.

  1. Numeric Integration using 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.m
fun = @(x) x.^2;
q = integral(fun, 0, 1)
41 chars
3 lines

This will return the answer as 0.3333.

  1. Multiple Integrations using 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.m
fun = @(x,y) (x+y).^2;
q = dblquad(fun, 3, 4, 1, 2)
52 chars
3 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.

related categories

gistlibby LogSnag