Académique Documents
Professionnel Documents
Culture Documents
Part 9: Integration
MATLAB can find both an indefinite integral (i.e., antiderivative) and a definite integral of a symbolic
expression. That assumes an elementary antiderivative exists. If not, MATLAB can compute a very
accurate numerical approximation to the definite integral.
syms x
Then enter
int(x*sin(x), x)
diff(ans, x)
2. Introduce another symbolic variable a to investigate how MATLAB deals with more than one
symbolic variable in integration. Enter:
syms a
Then enter
int(a*sin(x), x)
Now enter
int(a*sin(x), a)
MATLAB does not know an antiderivative of this function that can be defined in terms of
functions known to MATLAB. On the other hand, enter:
int(sin(x^2), x)
The Fresnel S function is known to MATLAB, but probably not to you. However, you can
check by differentiation that the expression is an antiderivative.
4. Next we calculate definite integrals. To integrate x sin(x) over the interval [0,pi/2], enter:
int(x*sin(x), x, 0, pi/2)
5. Now try this method on the integral of sin ( x5 + x3 ) over the interval [0,pi/2].
MATLAB still doesn't know an antiderivative for this function. To obtain a numerical estimate,
enter:
6. If you know that all you want is a numerical estimate, you can use MATLAB's numerical
integrator called quad8. No symbolics are involved. Enter:
Numerical integration also works with user-defined functions in m-files. Symbolic integration
doesn't. If you still have the m-file called fun.m that you created in Part 6 of this Tutorial, enter:
quad8('fun', 0, pi/2 )
The significance of using the quad8 function is that MATLAB does not try to find a symbolic
solution before starting on the numerical estimate.
7. Use MATLAB to find the exact value of each of the following integrals. (Type inf for the infinity
symbol.)
modules at math.duke.edu Copyright CCP and the author(s), 1998, 1999, 2000