


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
m. function value=rsum1(f,a,b,n) %RSUM1: Computes a Riemann Sum for the function f on %the interval [a,b] with a regular partition of n points. %The points on ...
Typology: Schemes and Mind Maps
1 / 4
This page cannot be seen from the preview
Don't miss anything!
Definition. Let f (x) be a function on an interval [a, b], and suppose this interval is parti- tioned by the values a = x 0 < x 1 < ... < xn− 1 < xn = b. Any sum of the form
∑^ n
k=
f (ck)△xk,
where △xk = xk − xk− 1 and ck ∈ [xk− 1 , xk] is referred to as a Riemann sum of f. If we let P denote our choice of partition (the choice of values x 0 , x 1 , ..., xn), and we let
‖P ‖ := max(△x 1 , △x 2 , ..., △xn)
denote the norm of this partition, then we say f is Riemann integrable if
lim ‖P ‖→ 0
∑^ n
k=
f (ck)△xk
exists. Following Leibniz, our notation for this limit is
∫ (^) b
a
f (x)dx = lim ‖P ‖→ 0
∑^ n
k=
f (ck)△xk.
Example 1. As our first example, we will consider the case in which ck is always chosen as the right endpoint of the interval [xk− 1 , xk]. If we take a regular partition with n intervals,
then each interval has length △x = b− na , and the kth endpoint is
xk = a + k△x.
The Riemann sum becomes
R =
∑^ n
k=
f (a + k△x)△x.
Suppose we would like to approximate the integral
∫ (^2)
0
e−x
2 dx
with n = 4. We have △x = 2 − 4 0 = .5 and the values
x 0 = 0 x 1 =. 5 x 2 = 1 x 3 = 1. 5 x 4 = 2. 0.
The Riemann sum is
k=
f (0 +. 5 k).5 = .5(e−.^5
2
2
2
2 ) =. 6352.
More generally, we can write a MATLAB function M-file that carries out this calculation for any function f (defined as an inline function), endpoints a and b and regular partition with n points. See rsum1.m.
function value=rsum1(f,a,b,n) %RSUM1: Computes a Riemann Sum for the function f on %the interval [a,b] with a regular partition of n points. %The points on the intervals are chosen as the right endpoints. value = 0; dx = (b-a)/n; for k=1:n c = a+kdx; value = value + f(c); end value = dxvalue;
We run this in MATLAB with the following lines in the Command Window.
f=inline(’exp(-xˆ2)’) f = Inline function: f(x) = exp(-xˆ2) rsum1(f,0,2,4) ans =
rsum1(f,0,2,10) ans =
rsum1(f,0,2,100) ans =
rsum1(f,0,2,1000) ans =
To four decimal places, the correct value is .8821. △ One interesting aspect of the Riemann sum is that the points ck need not be chosen in the same place on each interval. That is, suppose we partition the interval [0, 1] with 0 = x 0 < x 1 = 12 < x 2 = 1. In this case, a possible Riemann sum is
f (0)
0
e−x
2 dx
for regular partitions with n = 10, 100 , 1000.
0
e−x
2 dx
for regular partitions with n = 10, 100 , 1000.