Example 1:  f[x]=1/x

f[x_]:=1/x;  a=1; b=3;
FilledPlot[f[x],{x,a,b},AspectRatio->1]

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

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

n=1

n=1;
LEFT[n]=LeftEndpointRule[f[x],{x,a,b,n}]; {LEFT[n],N[LEFT[n]]}
[Graphics:../Images/simpson_gr_3.gif]
RIGHT[n]=RightEndpointRule[f[x],{x,a,b,n}];  {RIGHT[n],N[RIGHT[n]]}
[Graphics:../Images/simpson_gr_4.gif]
TRAP[n]=TrapezoidRule[f[x],{x,a,b,n}];  {TRAP[n],N[TRAP[n]]}
[Graphics:../Images/simpson_gr_5.gif]
MID[n]=MidpointRule[f[x],{x,a,b,n}];  {MID[n],N[MID[n]]}
[Graphics:../Images/simpson_gr_6.gif]
SIMP[n]=SimpsonRule[f[x],{x,a,b,n}];  {SIMP[n],N[SIMP[n]]}
[Graphics:../Images/simpson_gr_7.gif]

n=2

n=2;
LEFT[n]=LeftEndpointRule[f[x],{x,a,b,n}]; {LEFT[n],N[LEFT[n]]}
[Graphics:../Images/simpson_gr_8.gif]
RIGHT[n]=RightEndpointRule[f[x],{x,a,b,n}];  {RIGHT[n],N[RIGHT[n]]}
[Graphics:../Images/simpson_gr_9.gif]
TRAP[n]=TrapezoidRule[f[x],{x,a,b,n}];  {TRAP[n],N[TRAP[n]]}
[Graphics:../Images/simpson_gr_10.gif]
MID[n]=MidpointRule[f[x],{x,a,b,n}];  {MID[n],N[MID[n]]}
[Graphics:../Images/simpson_gr_11.gif]
SIMP[n]=SimpsonRule[f[x],{x,a,b,n}];  {SIMP[n],N[SIMP[n]]}
[Graphics:../Images/simpson_gr_12.gif]

n=3

n=3;
LEFT[n]=LeftEndpointRule[f[x],{x,a,b,n}]; {LEFT[n],N[LEFT[n]]}
[Graphics:../Images/simpson_gr_13.gif]
RIGHT[n]=RightEndpointRule[f[x],{x,a,b,n}];  {RIGHT[n],N[RIGHT[n]]}
[Graphics:../Images/simpson_gr_14.gif]
TRAP[n]=TrapezoidRule[f[x],{x,a,b,n}];  {TRAP[n],N[TRAP[n]]}
[Graphics:../Images/simpson_gr_15.gif]
MID[n]=MidpointRule[f[x],{x,a,b,n}];  {MID[n],N[MID[n]]}
[Graphics:../Images/simpson_gr_16.gif]
SIMP[n]=SimpsonRule[f[x],{x,a,b,n}];  {SIMP[n],N[SIMP[n]]}
[Graphics:../Images/simpson_gr_17.gif]

n=4

n=4;
LEFT[n]=LeftEndpointRule[f[x],{x,a,b,n}]; {LEFT[n],N[LEFT[n]]}
[Graphics:../Images/simpson_gr_18.gif]
RIGHT[n]=RightEndpointRule[f[x],{x,a,b,n}];  {RIGHT[n],N[RIGHT[n]]}
[Graphics:../Images/simpson_gr_19.gif]
TRAP[n]=TrapezoidRule[f[x],{x,a,b,n}];  {TRAP[n],N[TRAP[n]]}
[Graphics:../Images/simpson_gr_20.gif]
MID[n]=MidpointRule[f[x],{x,a,b,n}];  {MID[n],N[MID[n]]}
[Graphics:../Images/simpson_gr_21.gif]
SIMP[n]=SimpsonRule[f[x],{x,a,b,n}];  {SIMP[n],N[SIMP[n]]}
[Graphics:../Images/simpson_gr_22.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}]]
1.111111111111111111111111111109709
1.100000000000000000000000000005049
1.098941798941798941798941798941799
1.098725348725348725348725348725349
1.098660598660598660598660598660599
1.098636167753814812638342050106756
1.0986253798947297399309783210712
1.098620042680481501318760707642118
1.09861716481405089113618749729486425891
1.09861550485985172666599754913182927985
1.098614494075377186203676483953299
1.098613850565028551387414300909112
1.09861342534365829968602835639804939755
1.09861313535250332602521846374536915674
1.09861293214974479947644193013550799993
1.09861278637026849304925432154841095382
1.0986126796075726217349578352127205932
1.09861259998167768608732532590025076523
1.09861253962456759598989665194423504745
1.0986124932044732846352796317472602056
N[INT,20]
[Graphics:../Images/simpson_gr_23.gif]


Converted by Mathematica      February 18, 2001