166SCW, 7.7-Example 5: Error Bound Examples Involving Right Endpoint Sums and Left Endpoint Sums

Recall the Mathematica commands for approximation of
b
∫
a
f(x)x
with
L
n
or
R
n
:
In[]:=
LeftSum[f_,a_,b_,n_]:=
n
∑
i=1
f[a+(i-1)*(b-a)/n]*(b-a)/n
In[]:=
RightSum[f_,a_,b_,n_]:=
n
∑
i=1
f[a+i*(b-a)/n]*(b-a)/n
Let'slookatthedefiniteintegral
2
∫
-1
-
2
x
e
x:
In[]:=
f[x_]:=E^(-x^2)
Plot[f[x],{x,-1,2}]
Out[]=
(a) First we estimate this definite integral with
R
10
and
R
100
:
N[RightSum[f,-1,2,10]]
Out[]=
1.5704
N[RightSum[f,-1,2,100]]
Out[]=
1.6236
(b) Equation (4) can be used to determine how well these estimates approximate the definite integral. To apply this error estimate, we need to bound |f ' (x)| on [-1,2]. Here are two ways to do this:
​
​
​
(i) Graphically:
Plot[f'[x],{x,-1,2}]
Out[]=
Clearly,on[-1,2],|f'(x)|≤1,sotake
K
1
=1inEquation(4).Thenitfollowsthat​​ I-
R
10
≤
1*
2
(2+1)
2*10
=0.45​​and​​ I-
R
100
≤
1*
2
(2+1)
2*100
=0.045.​​​​Notethatmultiplyingthenumberofrectanglesby10causedtheestimateinerrortodecreasebyafactorof1/10!!!​​​​Whatdoyouthinkwouldhappentotheerrorboundifweused
R
1000
toestimateI?​​ ​​(ii)UsingCalculus:​​ ​​On[-1,2],sincef'iscontinuous,itmustattainitsmaximumandminimumvalues.Thesewilloccurateitherendpointsorcriticalpointsoff'.
f''[x]
Out[]=
-2
-
2
x

+4
-
2
x

2
x
Solve[f''[x]==0,x]
Out[]=
x-
1
2
,x
1
2

1./Sqrt[2]
Out[]=
0.707107
Since both solutions are in [-1,2], the places where |f '| can be maximized on [-1,2] are at x=-1, -1/
2
, 1/
2
, or x=2:
Abs[f'[{-1,-1/Sqrt[2],1/Sqrt[2],2}]]
Out[]=

2

,
2

,
2

,
4
4


N[%]
Out[]=
{0.735759,0.857764,0.857764,0.0732626}
Thus,wecantake
K
1
=
(2/E)
orabout0.857764.Thenitfollowsthat​​ I-
R
10
≤
2/E
*
2
(2+1)
2*10
=0.52462​​and​​ I-
R
100
≤
(2/E)
*
2
(2+1)
2*100
=0.052462
Using Mathematica, here is what we get numerically:
NIntegrate[E^(-x^2),{x,-1,2}]
Out[]=
1.62891
Compare to our estimates:
Abs[NIntegrate[E^(-x^2),{x,-1,2}]-RightSum[f,-1,2,10]]
Out[]=
0.0585105
Abs[NIntegrate[E^(-x^2),{x,-1,2}]-RightSum[f,-1,2,100]]
Out[]=
0.00530413