0% found this document useful (0 votes)
32 views

Numerical Report

The document presents the solution to estimating the total distance run by a train in 20 minutes using Simpson's 1/3 rule. It provides the velocity table, describes Simpson's 1/3 rule for numerical integration, shows the mathematical working to estimate the distance as 8.25 km using the rule, includes C++ code to implement the solution, and discusses some limitations and conclusions about Simpson's rule.

Uploaded by

Nilufar Yasmin
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

Numerical Report

The document presents the solution to estimating the total distance run by a train in 20 minutes using Simpson's 1/3 rule. It provides the velocity table, describes Simpson's 1/3 rule for numerical integration, shows the mathematical working to estimate the distance as 8.25 km using the rule, includes C++ code to implement the solution, and discusses some limitations and conclusions about Simpson's rule.

Uploaded by

Nilufar Yasmin
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

International Islamic University Chittagong

Department of Computer Science and Engineering


Project Report

Course code: 3608


Course tittle: Numerical method sessional
Submitted to:

Sanjida Sharmin
Lecturer,Dept of CSE

Submitted by:

Nilufar Yasmin
Id:C171271
Jannatul Ferdous Neela
Id:C171284R
Noora Jannat Sadia
Id:C181243
Project Tittle:
The velocity of a train which starts from rest is given by the following table, the time being reckoned in
minutes from the start and the speed in km/hour.
t(minutes) 2 4 6 8 10 12 14 16 18 20
v (km/hr) 16 28.8 40 46.4 51.2 32 17.6 8 3.2 0
Estimate approximately the total distance run in 20 minutes.

Method:
To solve this problem, we use Simpson’s 1/3 (one third) rule.

Description of Simpson’s 1/3 (one third) rule:


Consider General Quadrature formula,
I= h [n y0 + n2 / 2 Δy0 + ( n3 / 3 - n2 / 2 ) Δ2y0 / 2! + ( n4 / 4 - n3 + n2 ) Δ3y0 / 3! +…………]
Substituting n = 2 in the general quadrature formula and neglecting the third and other higher order
differences, we get
x 0+ 2 h
I1 =  x0
f (x) dx

= h [2y0 + 2Δy0 + (8 / 3 - 2) Δ2y0 / 2]


= h [2y0 + 2Δy0 + 1/3 Δ2y0]
= h [2y0 + 2 (y1 - y0) + 1/3 (y2 - 2y1 + y0)]
= 1/3 h [6y0 + 6y1 - 6y0 + y2 - 2y1 + y0]
= h/3 (y0 + 4y1 + y2)
Similarly, we get
x 0+ 4 h
I2 =  x 0+ 2 h
f (x) dx = h/3 (y2 + 4y3 + y4)

x 0+ 6 h
I3 =  x 0+ 4 h
f (x) dx = h/3 (y4 + 4y5 + y6)
.
.
x 0 + nh
In/2 =  x 0+ ( n − 2) h
f (x) dx = h/3 (yn-2 + 4yn-1 + yn)

Combining all these expressions, we obtain


I = I1 + I2 + …………. + In/2
= h/3 [(y0+4y1+y2) + (y2+4y3+y4) +……… + (yn-2+4yn-1+y2)]
= h/3 [y0 + 4 (y1 + y3 + y5 +....+ yn-1) + 2 ( y2 + y4 +.…+ yn-2) + yn]

The above formula is known as Simpson’s one-third rule on simply Simpson’s rule.
Mathematical Solution of given problem:
v =ds/dt ⇒ds= v.dt
⇒∫ds=∫ v.dt
20
s =∫ v.dt.
0
The train starts from rest, ∴ the velocity v = 0 when t = 0.
The given table of velocities can be written
t(minutes)/x 0 2 4 6 8 10 12 14 16 18 20
v (km/hr) 0 16 28.8 40 46.4 51.2 32 17.6 8 3.2 0
Y0 Y1 Y2 Y3 Y4 Y5 Y6 Y7 Y8 Y9 Y10
h = 2/60 hrs =1/30 hrs.
The Simpson’s 1/3 rule is given by
I = h/3[(y0 +y10) + 4(y1+y3+y5+y7+y9)+2(y2+y4+y6+y8)]
=1/30×3[(0+0)+4 (16+40+51.2+17.6+3.2)+2(28.8+46.4+32+8)]
=1/90[0+4×128+2×1152]
= 8.25 km.
∴ The distance run by the train in 20 minutes = 8.25 km.

Implementation:
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
int a,b,n,i;
double h;
ll k=0,j=0;
cout<<"Enter the total number of the intervals : ";
cin>>n;
double x[n+5]= {0},y[n+5]= {0},e[n+5]= {0},o[n+5]= {0};
cout<<"Enter the data of the time: \n";
for(int i=1; i<=n; i++)
{
cout<<"x["<<i<<"] : ";
cin>>x[i]; // t
}

cout<<"Enter the data of the velocity: \n";


for(int i=1; i<=n; i++)
{
cout<<"y["<<i<<"] : ";
cin>>y[i]; // v
}
h= (x[n]-x[0])/(n*60); // minutes to hour , 1 min = 1/60 hr , h= b-a/n
// cout<<h<<endl;
printf(" x[i]\t y[i]\n");
printf("x[0] : %.4f\ty[0] : %.4f\n",x[0],y[0]);
for(ll i=1; i<=n; i++)
{
if(i&1 && i!=n)
{
o[j]= y[i]; // odd number ,y1,y3,... odd check condition = i%2!=0 / i&1
j++;
}
else if(i!=n)
{
e[k]= y[i]; // even number ,y2,y4,...
k++;
}

printf("x[%lld] : %.4f\ty[%lld] : %.4f\n",i,x[i],i,y[i]);


}

double oddsum=0,evensum=0,res=0;
for(i=0; i<j; i++)
{
oddsum +=o[i];
}
for(i=0; i<k; i++)
{
evensum +=e[i];
}
// cout<<y[n]<<endl;
cout<<"\nAfter putting values in Simpon's 1/3 rule...\n";
res= h/(3.0) *((y[0]+y[n])+ (4.0*oddsum)+ (2.0*evensum));
printf("The distance run by the train in 20 minutes,I = %.4f km\n(correct to 4 significant figures)\n",res);
return 0;
}
/*
10
2
4
6
8
10
12
14
16
18
20
16
28.8
40
46.4
51.2
32
17.6
8
3.2
0
*/

Screenshot of output:
Limitations of Simpson’s rule

1. It is obviously inaccurate, i.e. there will always be a difference between it and the actual integral (except
in some cases, such as the area under straight lines).
2. Integrals allow you to get exact answers in terms of fundamental constants, which Simpson’s method
does not allow.
3. To get a good approximation to the real integral, it is necessary (often) to use a large number of
ordinates.

Conclusion

If f is a polynomial of up to third degree, the rule’s approximation equality becomes precise.


The composite Simpson’s rule is obtained by applying the 1/3 rule to n equal subdivisions of the integration
range [a, b]. Weights of 4/3 and 2/3 are alternated for points within the integration range.
Simpson’s approach, which approximates functions with quadratic polynomials, produces accurate results when
approximating integrals of functions.

You might also like