Example 3:  f[x]=x*Exp[-x^2]

f[x_]:=x*Exp[-x^2];  a=0; b=2;
FilledPlot[f[x],{x,a,b},AspectRatio->1]

[Graphics:../Images/simpson_gr_47.gif]

INT=Integrate[f[x],{x,a,b}]; {INT,N[INT]}
[Graphics:../Images/simpson_gr_48.gif]

n=1

n=1;
LEFT[n]=LeftEndpointRule[f[x],{x,a,b,n}]; {LEFT[n],N[LEFT[n]]}
[Graphics:../Images/simpson_gr_49.gif]
RIGHT[n]=RightEndpointRule[f[x],{x,a,b,n}];  {RIGHT[n],N[RIGHT[n]]}
[Graphics:../Images/simpson_gr_50.gif]
TRAP[n]=TrapezoidRule[f[x],{x,a,b,n}];  {TRAP[n],N[TRAP[n]]}
[Graphics:../Images/simpson_gr_51.gif]
MID[n]=MidpointRule[f[x],{x,a,b,n}];  {MID[n],N[MID[n]]}
[Graphics:../Images/simpson_gr_52.gif]
SIMP[n]=SimpsonRule[f[x],{x,a,b,n}];  {SIMP[n],N[SIMP[n]]}
[Graphics:../Images/simpson_gr_53.gif]

n=2

n=2;
LEFT[n]=LeftEndpointRule[f[x],{x,a,b,n}]; {LEFT[n],N[LEFT[n]]}
[Graphics:../Images/simpson_gr_54.gif]
RIGHT[n]=RightEndpointRule[f[x],{x,a,b,n}];  {RIGHT[n],N[RIGHT[n]]}
[Graphics:../Images/simpson_gr_55.gif]
TRAP[n]=TrapezoidRule[f[x],{x,a,b,n}];  {TRAP[n],N[TRAP[n]]}
[Graphics:../Images/simpson_gr_56.gif]
MID[n]=MidpointRule[f[x],{x,a,b,n}];  {MID[n],N[MID[n]]}
[Graphics:../Images/simpson_gr_57.gif]
SIMP[n]=SimpsonRule[f[x],{x,a,b,n}];  {SIMP[n],N[SIMP[n]]}
[Graphics:../Images/simpson_gr_58.gif]

n=3

n=3;
LEFT[n]=LeftEndpointRule[f[x],{x,a,b,n}]; {LEFT[n],N[LEFT[n]]}
[Graphics:../Images/simpson_gr_59.gif]
RIGHT[n]=RightEndpointRule[f[x],{x,a,b,n}];  {RIGHT[n],N[RIGHT[n]]}
[Graphics:../Images/simpson_gr_60.gif]
TRAP[n]=TrapezoidRule[f[x],{x,a,b,n}];  {TRAP[n],N[TRAP[n]]}
[Graphics:../Images/simpson_gr_61.gif]
MID[n]=MidpointRule[f[x],{x,a,b,n}];  {MID[n],N[MID[n]]}
[Graphics:../Images/simpson_gr_62.gif]
SIMP[n]=SimpsonRule[f[x],{x,a,b,n}];  {SIMP[n],N[SIMP[n]]}
[Graphics:../Images/simpson_gr_63.gif]

n=4

n=4;
LEFT[n]=LeftEndpointRule[f[x],{x,a,b,n}]; {LEFT[n],N[LEFT[n]]}
[Graphics:../Images/simpson_gr_64.gif]
RIGHT[n]=RightEndpointRule[f[x],{x,a,b,n}];  {RIGHT[n],N[RIGHT[n]]}
[Graphics:../Images/simpson_gr_65.gif]
TRAP[n]=TrapezoidRule[f[x],{x,a,b,n}];  {TRAP[n],N[TRAP[n]]}
[Graphics:../Images/simpson_gr_66.gif]
MID[n]=MidpointRule[f[x],{x,a,b,n}];  {MID[n],N[MID[n]]}
[Graphics:../Images/simpson_gr_67.gif]
SIMP[n]=SimpsonRule[f[x],{x,a,b,n}];  {SIMP[n],N[SIMP[n]]}
[Graphics:../Images/simpson_gr_68.gif]

Simpson's rule with n=1..20, as compared to exact answer

ColumnForm[Table[N[SimpsonRule[f[x],{x,a,b,n}],20],{n,20}]]
0.50271634748774588232317704104505
0.493731178939058126828021708695111
0.491265294520661674521401712921889
0.490966787193899807998565587128582
0.49089171187490852178922404547183
0.490865697958740182175048140258627
0.490854758770948751566658880235342
0.490849510538911688619415151468149
0.490846738428079025641188223011995
0.490845162518492790074402768055483
0.490844213032854617007672367967027
0.490843613353405374928876774806077
0.490843219527044403253079910024643
0.490842952245722670577208936518807
0.490842765682706372522807632021058
0.490842632263382203907345823966615
0.490842534807250321777965454242578
0.490842462280373795302980458480958
0.490842407405120137652192256786215
0.490842365266869503601681032415765
N[INT,20]
[Graphics:../Images/simpson_gr_69.gif]


Converted by Mathematica      February 18, 2001