You are on page 1of 3

In[201]:= f[x_ ] := 1 / (1 + x3);

m = 12;
a = 0; b = 1; n = m / 2; h = (b - a) / m;
m-1 m
APPINT = Nh / 3 f[a] + f[b] + 2  f[a + 2 k h] + 4  f[a + (2 k - 1) h] ;
k =1 k =1

EXACTINT = N[Integrate[f[x], {x, 0, 1}]];


Error = Abs[APPINT - EXACTINT];
Print["APPINT=", APPINT]
Print["EXACTINT=", EXACTINT]
Print["ERROR=", Error]
2.
APPINT=
1. + x3
1
EXACTINT=
1. + x3
1.
ERROR=
Abs[1. + x3]

In[219]:= f[x_ ] := 1 / (1 + x ^ 8);


m = Input["gives no.of partition"];
a = 0; b = 1; n = m / 2; h = (b - a) / m;
m-1 m
APPINT = Nh / 3 f[a] + f[b] + 2  f[a + 2 k h] + 4  f[a + (2 k - 1) h] ;
k =1 k =1

EXACTINT = N[Integrate[f[x], {x, 0, 1}]];


Error = Abs[APPINT - EXACTINT];
Print["APPINT=", APPINT]
Print["EXACTINT=", EXACTINT]
Print["ERROR=", Error]

ERROR=0.121112
EXACTINT=0.924652
APPINT=1.04576
ERROR=0.132546
EXACTINT=0.924652
APPINT=1.0572
APPINT=1.11746

EXACTINT=0.693147
ERROR=0.424313
2 kartikey18y.nb

In[73]:= f[x_ ] := 1 / (1 + x ^ 2);


m = 12;
a = 0; b = 1; n = m / 2; h = (b - a) / m;
m-1 m
APPINT = Nh / 3 f[a] + f[b] + 2  f[a + 2 k h] + 4  f[a + (2 k - 1) h] ;
k =1 k =1

EXACTINT = N[Integrate[f[x], {x, 0, 1}]];


Error = Abs[APPINT - EXACTINT];
Print["APPINT=", APPINT]
Print["EXACTINT=", EXACTINT]
Print["ERROR=", Error]

APPINT=1.11548
EXACTINT=0.785398
ERROR=0.330084

In[82]:= f[x_ ] := e ^ - x;
m = 12;
a = 0; b = 1; n = m / 2; h = (b - a) / m;
m-1 m
APPINT = Nh / 3 f[a] + f[b] + 2  f[a + 2 k h] + 4  f[a + (2 k - 1) h] ;
k =1 k =1

EXACTINT = N[Integrate[f[x], {x, 0, 1}]];


Error = Abs[APPINT - EXACTINT];
Print["APPINT=", APPINT]
Print["EXACTINT=", EXACTINT]
Print["ERROR=", Error]

1 1 1 1 1 1 1 1 1 1 1
APPINT=0.0277778 1. + 2. + + + + + + + + + + +
e11/6 e5/3 e3/2 e4/3 e7/6 e e5/6 e2/3 e e1/3 e1/6

1 1 1 1 1 1 1 1 1 1 1 1 1
4. + + + + + + + + + + + +
e23/12 e7/4 e19/12 e17/12 e5/4 e13/12 e11/12 e3/4 e7/12 e5/12 e1/4 e1/12 e

- 1. + e
EXACTINT=
e Log[e]

ERROR=Abs0.0277778

1 1 1 1 1 1 1 1 1 1 1 1 1
1. + 2. + + + + + + + + + + + 4. + +
e11/6 e5/3 e3/2 e4/3 e7/6 e e5/6 e2/3 e e1/3 e1/6 e23/12 e7/4

1 1 1 1 1 1 1 1 1 1 1 - 1. + e
+ + + + + + + + + + - 
19/12 17/12 5/4 13/12 11/12 3/4 7/12 5/12 1/4 1/12 e e Log[e]
e e e e e e e e e e
kartikey18y.nb 3

In[91]:= f[x_ ] := tan ^ - 1 x;


m = 12;
a = 0; b = 1; n = m / 2; h = (b - a) / m;
m-1 m
APPINT = Nh / 3 f[a] + f[b] + 2  f[a + 2 k h] + 4  f[a + (2 k - 1) h] ;
k =1 k =1

EXACTINT = N[Integrate[f[x], {x, 0, 1}]];


Error = Abs[APPINT - EXACTINT];
Print["APPINT=", APPINT]
Print["EXACTINT=", EXACTINT]
Print["ERROR=", Error]
1.97222
APPINT=
tan
0.5
EXACTINT=
tan
1.47222
ERROR=
Abs[tan]

You might also like