166SWC, 7.7 - Example 7: Simpson's (Parabolic) Rule and Error Bounds Discussion (Answers)
166SWC, 7.7 - Example 7: Simpson's (Parabolic) Rule and Error Bounds Discussion (Answers)
Recall the Mathematica commands for approximation of f(x)x with or :
b
∫
a
M
n
T
n
In[]:=
MidpointSum[f_,a_,b_,n_]:=f[a+(2*i-1)*(b-a)/(2*n)]*(b-a)/n
n
∑
i=1
In[]:=
Trapezoid[f_,a_,b_,n_]:=(1/2)(f[a+(i-1)*(b-a)/n]+f[a+i*(b-a)/n])*(b-a)/n
n
∑
i=1
1. Construct a command 'Simpson[f_,a_,b_,n_]' that will perform Simpson's rule and compute Sn.
Note that n must be even and Δx=(b-a)/n.
1. Construct a command 'Simpson[f_,a_,b_,n_]' that will perform Simpson's rule and compute .
Note that n must be even and Δx=(b-a)/n.
S
n
Note that n must be even and Δx=(b-a)/n.
In[]:=
Simpson1[f_,a_,b_,n_]:=1/3*Trapezoid[f,a,b,n/2]+2/3*MidpointSum[f,a,b,n/2]
In[]:=
Simpson2[f_,a_,b_,n_]:=(b-a)/(3*n)*Sum[f[a+(2*i-2)*(b-a)/n]+ 4*f[a+(2*i-1)*(b-a)/n]+f[a+2*i*(b-a)/n],{i,1,n/2}]
In[]:=
Simpson3[f_,a_,b_,n_]:=(b-a)/(3*n)*(f[a+(2*i-2)*(b-a)/n]+ 4*f[a+(2*i-1)*(b-a)/n]+f[a+2*i*(b-a)/n])
n/2
∑
i=1
2.Testthiscommandontheintegral 1∫0sin(x)xwithn=6andcomparetotheresultswefoundforapproximationsforthisintegralvia𝐿n,𝑅n,𝑀nand𝑇ninExample1.
2.Testthiscommandontheintegral sin(x)xwithn=6andcomparetotheresultswefoundforapproximationsforthisintegralvia,,andinExample1.
1
∫
0
𝐿
n
𝑅
n
𝑀
n
𝑇
n
Simpson1[Sin,0,1,6]
Out[]=
2
3
1
3
1
6
1
3
1
2
1
3
5
6
1
3
1
6
1
3
1
6
1
3
2
3
1
6
2
3
N[%]
Out[]=
0.4597
Simpson2[Sin,0,1,6]
Out[]=
1
18
1
6
1
3
1
2
2
3
5
6
N[%]
Out[]=
0.4597
Simpson3[Sin,0,1,6]
Out[]=
1
18
1
6
1
3
1
2
2
3
5
6
N[%]
Out[]=
0.4597
Comparing the result of =0.4597 to what we got in Example 1, namely =0.417241, =0.501388, =0.459889, and =0.459315, our estimate is closer to those for and , with about half the number of subintervals. Here’s the “actual” value of the integral:
S
6
L
10
R
10
M
10
T
10
M
10
T
10
NIntegrate[Sin[x],{x,0,1}]
Out[]=
0.459698
3. Find an upper bound for using Simpson’s Rule to estimate 1∫0sin(2x)x with even positive integer n. Test this out with n = 10. Here are some ideas that may be useful:
3. Find an upper bound for using Simpson’s Rule to estimate sin()x with even positive integer n. Test this out with n = 10. Here are some ideas that may be useful:
1
∫
0
2
x
To define the function ) with Mathematica, enter the command:
sin(
2
x
In[]:=
f[x_]:=Sin[x^2]
Here is how to find the fourth derivative of f:
f''''[x]
Out[]=
6(-4Cos[]-2Sin[])+2x(-8xCos[]-2x(2Cos[]-4Sin[]))
2
x
2
x
2
x
2
x
2
x
2
x
2
x
If this is too complicated, you can use the 'Simplify' command:
Simplify[%]
Out[]=
-48Cos[]+4(-3+4)Sin[]
2
x
2
x
4
x
2
x
Here is one way to graph f''''[x]:
Plot[f''''[x],{x,0,1},Frame->True]
Out[]=
From this graph, we see that on [0, 1], . Taking =30 in Equation (8), we have . Thus with n = 10, we have an upper bound for :
(x)<=30
(4)
f
K
4
I-<=(b-a)
S
n
5
K
4
180
4
n
|I-|
S
10
(30*(1)^5)/(180*10^4)
Out[]=
1
60000
N[%]
Out[]=
0.0000166667
Simpson1[f,0,1,10]
Out[]=
2
3
1
5
1
100
1
5
9
100
1
5
1
4
1
5
49
100
1
5
81
100
1
3
1
10
1
25
1
10
1
25
4
25
1
10
4
25
9
25
1
10
9
25
16
25
1
10
16
25
N[%]
Out[]=
0.31026
Integrate[Sin[x^2],{x,0,1}]//N
Out[]=
0.310268
%-%%
Out[]=
8.06729×
-6
10
4.FindthesmallestevenpositiveintegernsothatI-Sn<0.001for2∫-1-2xex.ComparethistowhatwefoundinExamples5and6.
4.FindthesmallestevenpositiveintegernsothatI-<0.001forx.ComparethistowhatwefoundinExamples5and6.
S
n
2
∫
-1
-
2
x
e
In[]:=
g[x_]:=E^(-x^2)
g''''[x]
Out[]=
-6-2+4-2x8x-2x-2+4
-
2
x
-
2
x
2
x
-
2
x
-
2
x
-
2
x
2
x
Simplify[%]
Out[]=
4(3-12+4)
-
2
x
2
x
4
x
Plot[g''''[x],{x,-1,2},Frame->True]
Out[]=
Solve[g'''''[x]==0,x]
Out[]=
{x0},x-+,x+,x-(5-,x(5-
5
2
5
2
5
2
5
2
1
2
10
)1
2
10
)N[%]
Out[]=
{{x0.},{x-2.02018},{x2.02018},{x-0.958572},{x0.958572}}
Ng''''-1,-5-,0,5-,2
1
2
10
1
2
10
Out[]=
{-7.35759,-7.41948,12.,-7.41948,1.39199}
Thus,on[-1,2],|g''''(x)|≤12,sowecantake=12inEquation(8)'serrorestimateforSimpson'sRule.Taken≥(((b-a)^5)/(180*0.001))^(1/4)
K
4
K
4
((12*(3)^5)/(180*0.001))^(1/4)