0% found this document useful (0 votes)
13 views1 page

Simpson

The document discusses the application of Simpson's rule for approximating the integral of the function 1/(1+x) from 0 to 1. It provides a method for calculating the integral using different values of n (2, 4, 6, 8) and shows that as n increases, the approximated value approaches the actual value of the integral, which is Log[2]. The final approximations for n=2, 4, 6, and 8 are given, demonstrating the accuracy of the method.

Uploaded by

vhsvansh01
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)
13 views1 page

Simpson

The document discusses the application of Simpson's rule for approximating the integral of the function 1/(1+x) from 0 to 1. It provides a method for calculating the integral using different values of n (2, 4, 6, 8) and shows that as n increases, the approximated value approaches the actual value of the integral, which is Log[2]. The final approximations for n=2, 4, 6, and 8 are given, demonstrating the accuracy of the method.

Uploaded by

vhsvansh01
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/ 1

Simpson’s rule

I(f)≈ h3 [f(a)+ 4 f  a2+b  +f(b)] where h = b- a


2

1
Q. Approximate the integral ∫0 1+1x  x using Simpson’s rule with n = 2.

In[1]:= simpson[a0_, b0_, n_, f_] :=


Module{a = a0, b = b0, h, approxintegral, m}, If[Mod[n, 2] ≠ 0,
b-a
Print["n should be even positive integer"]; Return[];]; h = ;
n
n
m= ;
2
h 2h m-1 4h m
approxintegral = (f[a] + f[b]) +  f[a + 2 k h] +  f[a + (2 k - 1) h];
3 3 k=1 3 k=1

Return[approxintegral];;
1
f[x_] := ; N[simpson[0, 1, 2, f]]
1+x
Out[2]= 0.694444

1
Q. Approximate the integral ∫0 1+1x  x using composite Simpson’s rule with n = 4,6,8.

In[3]:= N[simpson[0, 1, 4, f]]


Out[3]= 0.693254

In[4]:= N[simpson[0, 1, 6, f]]


Out[4]= 0.69317

In[5]:= N[simpson[0, 1, 8, f]]


Out[5]= 0.693155

1 1
In[6]:= actualvalue =  x
0 1+x
Out[6]= Log[2]

In[7]:= N[actualvalue]
Out[7]= 0.693147

Note: As n increases the approximated value tends to actual value of integral.

You might also like