0% found this document useful (0 votes)
34 views6 pages

Simpson Rule

Simpson rule example .

Uploaded by

psoni20112003
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views6 pages

Simpson Rule

Simpson rule example .

Uploaded by

psoni20112003
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

SIMPSON RULE :

Question 1)Find the integral in the interval of(0,1) of the


function f(x)=1+x using Simpson rule.
In[103]:=

f[x_] = 1 + x;
lowlimit = a = 0;
upplimit = b = 1;
fa = f[a];
fb = f[b];
h = (b - a)  2;
c = h * fa + 4 f[a + h] + fb  3;
Print"(Simpson rule)integral = ", c;
3
(Simpson rule)integral =
2
In[112]:=
Print"The area approximated value by Simpson rule is ", N[c]
Print"Original value of integral is ", N[int], " and the error is ", N[c] - N[int];

The area approximated value by Simpson rule is 1.5


Original value of integral is 1.5 and the error is 0.

Question 2)Find the integral in the interval of(1,2) of the


function f(x)=1+x using Simpson rule.
In[165]:=

f[x_] = 1 + x;
lowlimit = a = 1;
upplimit = b = 2;
fa = f[a];
fb = f[b];
int = Integrate[f[x], {x, a, b}];
h = (b - a)  2;
c = h * fa + 4 f[a + h] + fb  3;
Print"(Simpson rule)integral = ", c;
Print"The area approximated value by Simpson rule is ", N[c]
Print"Original value of integral is ", N[int], " and the error is ", N[c] - N[int];
2

5
(Simpson rule)integral =
2
The area approximated value by Simpson rule is 2.5
Original value of integral is 2.5 and the error is 0.

Question 3)Find the integral in the interval of(1,2) of the


function f(x)=x^2+2x+7 using Simpson rule and find the
error also.
In[123]:=
f[x_] = x ^ 2 + 2 x + 7;
lowlimit = a = 1;
upplimit = b = 2;
fa = f[a];
fb = f[b];
h = (b - a)  2;
c = h * fa + 4 f[a + h] + fb  3;
Print"(Simpson rule)integral = ", c;
37
(Simpson rule)integral =
3
In[132]:=
int = Integrate x ^ 2 + 2 x + 7, {x, a, b}
Out[132]=
37
3

In[133]:=
Print"The area approximated value by Simpson rule is ", N[c]
Print"Original value of integral is ", N[int], " and the error is ", N[c] - N[int];

The area approximated value by Simpson rule is 12.3333


Original value of integral is 12.3333 and the error is 0.
3

Question 4)Find the integral in the interval of(1,2) of the


function f(x)=x^4-3x^2+5x-17 using Simpson rule and find
the error also.
In[143]:=
f[x_] = x ^ 4 - 3 x ^ 2 + 5 x - 17 ;
lowlimit = a = 1;
upplimit = b = 2;
fa = f[a];
fb = f[b];
h = (b - a)  2;
c = h * fa + 4 f[a + h] + fb  3;
Print"(Simpson rule)integral = ", c;
247
(Simpson rule)integral = -
24
In[151]:=
int = Integratex ^ 4 - 3 x ^ 2 + 5 x - 17 , {x, a, b}
Out[151]=
103
-
10

In[152]:=
Print"The area approximated value by Simpson rule is ", N[c]
Print"Original value of integral is ", N[int], " and the error is ", N[c] - N[int];

The area approximated value by Simpson rule is - 10.2917

Original value of integral is - 10.3 and the error is 0.00833333


4

◼ COMPARISON BETWEEN TRAPEZOIDAL AND SIMPSON'S


RULE :

Question 1)Find the integral in the interval of(1,2) of the


function f(x)=x^3-9x+13 using Simpson rule and
trapezoidal rule .find the error also.
In[212]:=
f[x_] = x ^ 3 - 9 x + 13 ;
lowlimit = a = 1;
upplimit = b = 2;
fa = f[a];
fb = f[b];
h = b - a;
trap = Nh fa + fb  2;
simps = Nh * fa + 4 f(a + b)  2 + fb  6;
exactvalue = NIntegratex ^ 3 - 9 x + 13, {x, 1, 2};
Print"Approximate value using trapezoidal rule = ", N[trap];
Print"Approximate value using trapezoidal rule = ", N[simps]
Print"Exact value = ", exactvalue
error1 = Abs[trap - exactvalue];
error2 = Abs[simps - exactvalue];
Print"Error in trapezoidal rule = ", error1;
Print"Error in simpson rule = ", error2;
Iferror2 < error1 , Print"Simpson 's rule gives more acurate value. ",
Print"Trapezoidal's rule gives more acurate value. ";

Approximate value using trapezoidal rule = 4.


Approximate value using trapezoidal rule = 3.25
Exact value = 3.25
Error in trapezoidal rule = 0.75
Error in simpson rule = 0.
Simpson 's rule gives more acurate value.

Question 2)Find the integral in the interval of(1,2) of the


function f(x)=1/X using Simpson rule and trapezoidal rule
5

.find the error also.


In[193]:=
f[x_] = 1/x ;
lowlimit = a = 1;
upplimit = b = 2;
fa = f[a];
fb = f[b];
h = b - a;
trap = Nh fa + fb  2;
simps = Nh * fa + 4 f(a + b)  2 + fb  6;
exactvalue = NIntegratex ^ 3 - 9 x + 13, {x, 1, 2};
Print"Approximate value using trapezoidal rule = ", N[trap];
Print"Approximate value using trapezoidal rule = ", N[simps]
Print"Exact value = ", exactvalue
error1 = Abs[trap - exactvalue];
error2 = Abs[simps - exactvalue];
Print"Error in trapezoidal rule = ", error1;
Print"Error in simpson rule = ", error2;
Iferror2 < error1 , Print"Simpson 's rule gives more acurate value. ",
Print"Trapezoidal's rule gives more acurate value. ";

Approximate value using trapezoidal rule = 0.75


Approximate value using trapezoidal rule = 0.694444
Exact value = 3.25
Error in trapezoidal rule = 2.5
Error in simpson rule = 2.55556
Trapezoidal's rule gives more acurate value.
6

Simpson 3/8 Rule :


Question 1)Find the integral in the interval of(0,1) of the
function f(x)=1+x using Simpson 3/8 rule.
In[229]:=

f[x_] = 1 + x;
lowlimit = a = 0;
upplimit = b = 1;
fa = f[a];
fb = f[b];
h = (b - a)  3;
c = 3 h fa + 3 f[a + h] + 3 fa + 2 h + fb  8;
Print"integral = ", c;
3
integral =
2

Question 2)Find the integral in the interval of(0,1) of the


function f(x)=x^2+1 using Simpson 3/8 rule.
In[237]:=
f[x_] = x ^ 2 + 1;
lowlimit = a = 0;
upplimit = b = 1;
fa = f[a];
fb = f[b];
h = (b - a)  3;
c = 3 h fa + 3 f[a + h] + 3 fa + 2 h + fb  8;
Print"integral = ", c;
4
integral =
3

You might also like