10.1 Riemann Sum
MATLAB has a command rsums
that allows you to graphically explore
Riemann sums. Here is an example.
Find ò01 e-3x dx
>> rsums exp(-3*x)
MATLAB has given you a window (you may have to click on windows and
then on figure no. 1) which shows the Riemann sums for exp(-3*x
on the interval [0,1] when n
To increase n
, click on the right arrow at the bottom.
The value of the Riemann sum is shown above the graph.
You can watch this value change as you increase n
Compare this answer to
With the command
you can only use the
interval [0,1] and you can only use the maximum n
allowed by this
10.2 Simpson's Rule and other numerical methods
10.3 Symbolic integration
MATLAB has a built in ability to compute symbolic integrals. You will
need to be familiar with the
operations to fully appreciate this.
Note: MATLAB has improved and different symbolic math
capabilities in version 5.0 and greater. These notes refer to earlier
- Finding Antiderivatives
Use MATLAB to compute ò e-3xdx.
Of course you know how to find this easy antiderivative by hand.
But we'll use it to illustrate how to find integrals using MATLAB.
-1/3 * exp (-3*x)
We know the answer should be -(1/3)e-3x +C, with a
``constant of integration" C.
MATLAB omits this constant, but that doesn't mean you should!
- finding a second derivative
MATLAB has found the antiderivative of the last answer namely the
antiderivative of -1/3 * exp (-3*x).
one can use the
command to recover the integrand:
- Finding definite integrals
MATLAB can compute definite integrals as well.
>>int ('exp (-3*x)', 0, 1)
ans = -1/3 * exp (-3)+1/3
This computed the following ò01 e-3x dx.
- numeric answers
What if you wanted a number? You can use the
>> numeric % for the last integral done above
ans = .3167
- Simplifying messy integration
Often the answer MATLAB gives is quite hard to read. It has a built
in simplify command to help in these cases:
>> int('sin(x)^7 * cos(x)^5')
ans = TOO UGLY TO PRINT
To see how MATLAB simplifies this answer, use the
command and then the
>> simplify % simplifies the last integral
>> pretty % makes it _pretty_
Do this example with MATLAB. Is it ``prettier''?
- When there is no antiderivative
Sometimes there is just no antiderivative for a given function. So
Fundamental Theorem of Calculus
will offer no
help in finding an answer to a definite integral. You need to
approximate the answer if you want to move on. Again we use
the MATLAB command
. As well, you could approximate
the integral with a
, or use
>> int('\cos(x^3)', 0,1) % if MATLAB chokes it prints out its input
ans = int('\cos(x^3)', 0,1)
>> numeric % find numeric answer to last query
ans = 0.9317
10.4 Multiple integration