Date post: | 08-Apr-2018 |
Category: |
Documents |
Upload: | vijay-raj-punia |
View: | 233 times |
Download: | 3 times |
of 49
8/7/2019 Applied Numerical Technique Lab Mannual
1/49
Applied NumericalTechniques AndComputing File
Submitted by:
8/7/2019 Applied Numerical Technique Lab Mannual
2/49
VIJAY PUNIA
(7 ME 131-L)
INDEX
SNO. OBJECTIVE DATE SIGN REMARK
1Solution of non linear equationin single variable using themethod of SUCCESSIVEBISECTION.
11/AUG/09
2
Solution of non linear equation
in single variable using theNEWTON RAPHSON METHOD.
18/AUG/09
3Solution of a system ofsimultaneous algebraicequations using the GUASSIANELIMINATION PROCEDURE.
25/AUG/09
4Solution of a system ofsimultaneous algebraicequations using the GUASSJORDAN PROCEDURE.
01/SEP/09
5
Solution of a system of
simultaneous algebraicequations using the GUASSSEIDAL ITERATIVE METHOD.
08/SEP/09
6Numerical solution of anordinary differential equationusing the EULERS METHOD.
15/SEP/09
7Numerical solution of anordinary differential equation 22/SEP/0
8/7/2019 Applied Numerical Technique Lab Mannual
3/49
using the RUNGE KUTTA 4TH
ORDER METHOD.9
8Numerical solution of anordinary differential equationusing the PREDICTOR
CORRECTOR METHOD.
29/SEP/09
9Numerical solution of systemof two ordinary differentialequation using theTRAPEZOIDAL RULE
6/OCT/09
10Numerical solution of systemof two ordinary differentialequation using the SIMPSONSRULE
27/OCT/09
EXPERIMENT -1
OBECTIVE:- Solution of non linear equation in single variable using method of successiveBISECTION.
BISECTION METHOD
This method is based on the repeated application of the intermediate value property. Let thefunction f(x) be continuous between a and b. for the definiteness, let f(a)be negative and f(b) bepositive . then first approximation to the root is x1=(a+b)/2.
If f(x1)=0, then x1is the root of f(x)=0. Otherwise the root lies between a and x1 or x1 and baccording as f(x1) is positive or negative. Then we bisect the interval as before and continue theprocess until the root is found to desired accuracy.
In the fig. 1, f(x1) is positive, so that the root lies between a and x 1. Then the second approximationto the root root is x2=(a+x1)/2. If f(x2) is ve, the root lies between x1 and x2. Then thirdapproximation to he root is x3=(x1+x2)/2 and so on.
8/7/2019 Applied Numerical Technique Lab Mannual
4/49
FIG. 1
FLOW CHART
8/7/2019 Applied Numerical Technique Lab Mannual
5/49
PROGRAME IN C
#include
8/7/2019 Applied Numerical Technique Lab Mannual
6/49
#include
#include
# define f(x) (x*x*x-4*x-9)
void main(){
int i;
float a,b,x,eps,y,y1,y2;
clrscr();
printf("enter the value of a=\t");
scanf("%f",&a);
printf("enter the value of b=\t");
scanf("%f",&b);
y1=f(a);
y2=f(b);
if(y1*y2>0)
{
printf("wrong braketting");
}
else
{
printf("enter the value of eps=\t");
scanf("%f",&eps);
i=1;
do
{
x=(a+b)/2;
y=f(x);
8/7/2019 Applied Numerical Technique Lab Mannual
7/49
if(y1*yeps);
}
getch();
}
COMPUTER SOLUTION
8/7/2019 Applied Numerical Technique Lab Mannual
8/49
Enter the value of a =2
Enter the value of b =3
Enter the value of eps = .0001
No. of iterations i=1Approx root of the equation is x=2.50000
No. of iterations i=2
Approx root of the equation is x=2.75000
No. of iterations i=3
Approx root of the equation is x=2.62500
No. of iterations i=4
Approx root of the equation is x=2.68750
No. of iterations i=5
Approx root of the equation is x=2.71875
No. of iterations i=6
Approx root of the equation is x=2.70313
No. of iterations i=7
Approx root of the equation is x=2.71094
No. of iterations i=8
Approx root of the equation is x=2.70703
No. of iterations i=9
Approx root of the equation is x=2.70508
No. of iterations i=10
Approx root of the equation is x=2.70605
No. of iterations i=11
Approx root of the equation is x=2.70654
No. of iterations i=12
Approx root of the equation is x=2.70630
8/7/2019 Applied Numerical Technique Lab Mannual
9/49
No. of iterations i=13
Approx root of the equation is x=2.70642
No. of iterations i=14
Approx root of the equation is x=2.70648
8/7/2019 Applied Numerical Technique Lab Mannual
10/49
EXPERIMENT 2
OBJECTIVE:- Solution of non linear equation in single variable using NEWTON RAPHSONmethod.
NEWTON RAPHSON
Let x0 be an approximate root of the equation f(x)=0. If x1=x0+h be the exact root then f(x1)=0.
Therefore expanding f(x0+h) by tayolors series f(x0)+h f(x0)+h2f(x0)/2!+..=0
Since h is small, neglecting h2 and higher power of h, we get f(x0)+h f(x0)=0
Or h=-(f(x0)/f(x0))
Therefore a closer approximation to the root is given by
X1=x0 - (f(x0)/f(x0))
Similarly starting with x1, a still better approximation x2 is given by
X2=x1- (f(x0)/f(x0))
In general,
Xn+1=xn - (f(xn)/f(xn))
8/7/2019 Applied Numerical Technique Lab Mannual
11/49
FLOW CHART
8/7/2019 Applied Numerical Technique Lab Mannual
12/49
PROGRAMING IN C
#include
#include
#include#define f(x)(x*x*x-6*x+4)
#define df(x)(3*x*x-6)
void main()
{
int i,n;
float eps,h,x0,x1,error;
clrscr();
printf("enter the value of x0 and eps\n");
scanf("%f%f",&x0,&eps);
printf("enter the value of n\n");
scanf("%d",&n);
for(i=1;i
8/7/2019 Applied Numerical Technique Lab Mannual
13/49
COMPUTER SOLUTION
Enter the value of x0 and eps
1
.00001Enter the value of n
7
No. of iterations i=1
Approx root of the equation is x=.620016
No. of iterations i=2
Approx root of the equation is x=.607121
No. of iterations i=3
Approx root of the equation is x=.607102
No. of iterations i=4
Approx root of the equation is x=.607102
No. of iterations i=5
Approx root of the equation is x=.607102
No. of iterations i=6
Approx root of the equation is x=.607102
No. of iterations i=7
Approx root of the equation is x=.607102
8/7/2019 Applied Numerical Technique Lab Mannual
14/49
EXPERIMENT 3
OBJECTIVE:-Solution of a system of simultaneous algebraic equations using the GUASSIANELIMINATION PROCEDURE.
GUASSIAN ELIMINATION
In this method, the unknowns are eliminated successively and the system is reduced to an uppertriangular system from which the unknown are found by back substitution. The method is quitegeneral and is well adapted computer operations. Here we shall explain it by considering a systemof three equations for sake of clarity.
Consider the equations
a1x+b1y+c1z=d1
a2x+b2y+c2z=d2a3x+b3y+c3z=d3 .1
Step I: - To eliminate x from second and third equations.
Assuming a1=! 0, we eliminate x from second equation by subtracting (a2/a1) times the firstequation from second equation. Similarly we eliminate x from third equation by subtracting(a3/a1) times the first equation from third equation. We thus, get the new system
a1x+b1y+c1z=d1
b2y+c2z=d2
b3y+c3z=d3 .2
Here the first equation is called pivotal equation and a1 is called the first pivot.
Step II: - To eliminate y from third equations in (2)
Assuming b2=! 0, we eliminate y from third equation of (2), by subtracting (b3/b2) timesthe second equation from third equation. We thus, get the new system
a1x+b1y+c1z=d1
b2y+c2z=d2
c3z=d3 .3
Here the second equation is called the pivotal equation in (2)
Step III: - To evaluate the unknowns.
The values of x, y, z are found from the reduced system (3) by back substitution.
8/7/2019 Applied Numerical Technique Lab Mannual
15/49
8/7/2019 Applied Numerical Technique Lab Mannual
16/49
PROGRAMING IN C
#include
#include
#include#define n 4
void main()
{
float a[n][n+1],x[n],s,t;
int i,j,k;
clrscr();
printf("enter the agumented matrix rowwise\n");
for(i=0;i
8/7/2019 Applied Numerical Technique Lab Mannual
17/49
for(i=0;i
8/7/2019 Applied Numerical Technique Lab Mannual
18/49
COMPUTER SOLUTION
Enter the elements of augmented matrix row wise.
10 -7 3 5 6
-6 8 -1 -4 53 1 4 11 2
5 -9 -2 4 7
The upper triangular matrix is:-
10.000 -7.000 3.000 5.000 6.000
0.000 3.800 0.800 -1.000 8.600
0.000 0.000 2.447 10.315 -6.815
0.000 0.000 0.000 9.924 9.924
The solution is:-
X[1] = 5.000
X[2] = 4.000
X[3] = -7.000
X[4] = 1.000
8/7/2019 Applied Numerical Technique Lab Mannual
19/49
EXPERIMENT 4
OBJECTIVE:- Solution of a system of simultaneous algebraic equations using the GUASSJORDAN PROCEDURE.GAUSS JORDAN
This is modification of gauss elimination method. In this method, elimination of unknowns isperformed not in the equation below but also in the equation above, ultimately reducing the systemin diagonal matrix form i.e. each equation involving only one unknown. From these equations theunknowns x, y, z xan be obtained readily.
Thus in this method, the labour of back substitution for finding the unknowns is saved atthe cost of additional calculation. . Here we shall explain it by considering a system of three
equations for sake of clarity.Consider the equations
a1x+b1y+c1z=d1
a2x+b2y+c2z=d2
a3x+b3y+c3z=d3 .1
Step I: - To eliminate x from second and third equations.
Assuming a1=! 0, we eliminate x from second equation by subtracting (a2/a1) times the first
equation from second equation. Similarly we eliminate x from third equation by subtracting(a3/a1) times the first equation from third equation. We thus, get the new system
a1x+b1y+c1z=d1
b2y+c2z=d2
b3y+c3z=d3 .2
Here the first equation is called pivotal equation and a1 is called the first pivot.
Step II: - To eliminate y from third equations in (2)
Assuming b2=! 0, we eliminate y from first and third equation of (2), by subtracting(b2/b1) times the second equation from first equation. Similarly we eliminate y by subtracting(b2/b3) times the second equation from third equation. We thus, get the new system
a1x+ c1z=d1
b2y+c2z=d2
8/7/2019 Applied Numerical Technique Lab Mannual
20/49
c3z=d3 .3
Here the second equation is called the pivotal equation in (2)
Step II: - To eliminate y from third equations in (2)
Assuming c3=! 0, we eliminate z from first and second equation of (3), by subtracting(c3/c1) times the third equation from first equation. Similarly we eliminate y by subtracting(c3/c2) times the third equation from second equation. We thus, get the new system
a1x =d1
b2y =d2
c3z=d3 .3
8/7/2019 Applied Numerical Technique Lab Mannual
21/49
FLOW CHART
8/7/2019 Applied Numerical Technique Lab Mannual
22/49
PROGRAMING IN C
#include
#include#include
#define n 3
void main()
{
float a[n][n+1],x[n],t;
int i,j,k;
clrscr();
printf("enter the agumented matrix rowwise\n");
for(i=0;i
8/7/2019 Applied Numerical Technique Lab Mannual
23/49
for(k=0;k
8/7/2019 Applied Numerical Technique Lab Mannual
24/49
COMPUTER SOLUTION
Enter the elements of augmented matrix row wise.10 -7 3 5 6
-6 8 -1 -4 5
3 1 4 11 2
5 -9 -2 4 7
The upper triangular matrix is:-
10.000 0.000 0.000 0.000 50.000
0.000 3.800 0.000 0.000 15.200
0.000 0.000 2.447 0.000 -17.131
0.000 0.000 0.000 9.924 9.924
The solution is:-
X[1] = 5.000
X[2] = 4.000
X[3] = -7.000
X[4] = 1.000
8/7/2019 Applied Numerical Technique Lab Mannual
25/49
EXPERIMENT 5
OBJECTIVE:- Solution of a system of simultaneous algebraic equations using the GUASSSEIDAL ITERATIVE METHOD.
GUASS SEIDAL ITERATIVE METHOD
The preceding methods of solving simultaneous linear equation are known as direct methods, asthese methods yield the solution after a certain amount of fixed computation. On the other hand, aniterative method is that in which we start from an approximation to the true solution and obtainbetter and better approximations from a computation cycle repeated as often as may be necessaryfor achieving a desired accuracy. Thus in an iterative method, the amount of computation depends
on the degree of accuracy required. As before the system of equations:a1x+b1y+c1z=d1
a2x+b2y+c2z=d2
a3x+b3y+c3z=d3 .1
is written as x=( d1-b1y-c1z)/ a1
y= (d2-a2x-c2z)/ b2
z= (d3-a3x-b3y)/ c3 .2
Here also we start with the initial approximations x0, y0, z0 for x, y, z respectively which may eachbe taken as zero. Substituting y=y0, z=z0 in the first of the equation (2), we have
x1=( d1-b1y0-c1z0)/ a1
Then putting x=x1, z=z0 in the second of the equation (2), we have
y1= (d2-a2x0-c2z0)/ b2
Next substituting x=x1, y=y1 in the third of the equation (2), we have
z1= (d3-a3x1-b3y1)/ c3
and so on i.e. as soon as a new approximation for an unknown is found, it is immediately used inthe next step.
This process of iteration is repeated till the values of x, y, z are obtained to desire degree ofaccuracy.
8/7/2019 Applied Numerical Technique Lab Mannual
26/49
FLOW CHART
8/7/2019 Applied Numerical Technique Lab Mannual
27/49
PROGRAMING IN C
#include
#include
#include#define n 4
void main()
{
float a[n][n+1],x[n],aerr,maxerr,t,s,err;
int i,j,itr,maxitr;
clrscr();
//first initialising array x
for(i=0;i
8/7/2019 Applied Numerical Technique Lab Mannual
28/49
{
s=0;
for(j=0;jmaxerr)
maxerr=err;
x[i]=t;
}
printf(("%d",itr);
for(i=0;i
8/7/2019 Applied Numerical Technique Lab Mannual
29/49
COMPUTER SOLUTION
Enter the elements of augmented matrix row wise.20 1 -2 17
3 20 -1 -18
2 -3 20 25
Enter the allowed error , maximum iterations
.0001 10
Iteration x[1] x[2] x[3]
1 0.8500 -1.0275 1.0109
2 1.0025 -0.9998 0.9998
3 1.0000 -1.0000 1.0000
4 1.0000 -1.0000 1.0000
Converges in 4 iterations
X[1] = 1.0000
X[2] = -1.0000
X[3] = 1.0000
8/7/2019 Applied Numerical Technique Lab Mannual
30/49
EXPERIMENT - 6
OBJECTIVE : Numerical solution of an ordinary differential equation using the EULERSMETHOD.
EULERS METHOD.
Consider the equation (1)
Given that y(x0)=y0. Its a curve of solution through p(x0,y0) is shown in figure. Now we have tofind the ordinate of any other point Q on the curve.
Let us divide LM into n sub intervals each of width h at L1 .L2 . So that h is quite small.
In the interval LL1, we approximate the curve by tangent at P. If the ordinate through L 1 meets thistangent in P1(x0+h,y1), then
y1=L1P1=LP+R1P1=y0+PR1 tan
=y0+h =y0+h f(x0,y0)
Let P1Q1 be the curve of the solution of (1) through P1 and let its tangent at P1 meet the ordinatethrough L2 in the P2(x0+2h,y2). Then
y2=y1+hf(x0+h,y1) .(1)Repeating this process n times, we finally reach on an approximation MPn of MQ given by
yn=yn-1+hf(x0+(n-1)h,yn-1)
This is Eulers method of finding an approximate solution of (1)
8/7/2019 Applied Numerical Technique Lab Mannual
31/49
FLOW CHART
8/7/2019 Applied Numerical Technique Lab Mannual
32/49
PROGRAMING IN C
#include
#include
#include
#define f(x,y) (x+y*y)
void main()
{
clrscr();
int i,n;
float h,y,x,x0,y0,t;
printf("Enter the number of iteration\n");
scanf("%d",&n);
printf("Enter the value of x0\n");
scanf("%f",&x0);
printf("Enter the value of y0\n");
scanf("%f",&y0);
printf("Enter the value of h\n");
scanf("%f",&h);
y=y0;
for(i=0;i
8/7/2019 Applied Numerical Technique Lab Mannual
33/49
COMPUTER SOLUTION
Enter the number of iteration
5
Enter the value of x0
0
Enter the value of y0
1
Enter the value of h
0.1
The value of y in the 0stiteration=1.1
The value of y in the 1stiteration=1.231
The value of y in the 2stiteration=1.402536
The value of y in the 3stiteration=1.629247
The value of y in the 4stiteration=1.934692
8/7/2019 Applied Numerical Technique Lab Mannual
34/49
EXPERIMENT 7
OBJECTIVE: Numerical solution of an ordinary differential equation using the RUNGE KUTTA 4TH ORDER METHOD.
RUNGE KUTTA METHOD.
The Taylors series method of solving differential equations numerically is restricted by thelabour involved in finding the higher order derivatives . however there is class of methods knownas Runge-Kutta methods which do not require the calculations of higher order derivatives and givegreater accuracy . The Runge-Kutta formulae possess the advantage of requiring only the functionvalues at some selected points. These methods agree with Taylors series solution upto the term inhr where r differs from method to method and is called the order of that method.
RUNGE KUTTA 4TH ORDER METHOD.
This method is most commonly used and is often referred to as Runge-Kutta method only.
Working Rule for finding the increment k of y corresponding to an increment h of x by Runge-Kutta method from
y(x0)=y0
is as follows :
Calculate successively
k1= h*f(x0,y0)
k2=h*f(x0+1/2h,y0+1/2k1)
k3=h*f(x0+1/2h,y0+1/2k2)
k4=h*f(x0+1/2h,y0+1/2k3)
Finally compute
k= +(k 1+2k2+2k3+k4)
Which gives the required approximate value as y1=y0+k.
8/7/2019 Applied Numerical Technique Lab Mannual
35/49
FLOW CHART
8/7/2019 Applied Numerical Technique Lab Mannual
36/49
8/7/2019 Applied Numerical Technique Lab Mannual
37/49
COMPUTER SOLUTION
Enter the value of x0
0
Enter the value of y0
1
Enter the value of h
0.2
x=0.2
y=1.2688
8/7/2019 Applied Numerical Technique Lab Mannual
38/49
EXPERIMENT 8
OBJECTIVE:Numerical solution of an ordinary differential equation using the PREDICTORCORRECTOR METHOD.
PREDICTORCORRECTOR METHOD.
If xi-1 and xi be the two consecutive mesh points we have xi =xi-1+h. In the Eulers methodwe have
yi=yi-1+hf(x0+Ei-1h,yi-1);i=1,2,3..
The modified Eulers method
yi=yi-1+h/2[f(xi-1,yi-1)+f(xi,yi)]
The value of yi is first estimated by using (1), then this value is inserted on the right side of(2), giving better approximation of yi. This value of yi is again then substituted in (2) to find a still better approximation of yi. This step is repeated till two consecutive values of y i agree. Thistechnique of refining an initially crude estimate of yi by means of more accurate formula is known
as predictor- corrector method. The equation (1) is therefore called as predictor while (2) serves asa corrector of yi.
In this method so far described to solve a differential equation over an interval, only thevalue of y at the beginning of the interval was required. In the predictor-corrector methods, fourprior values are needed for finding the value of y at x i. Though slightly complex these methodshave the advantage of giving an estimate of error from successive approximations to yi.
We have two such methods, namely : Milnes method and Admas-Bashforth method.
MILNES METHOD
Given dy/dx=f(x,y) and y=y0, x=x0; to find an approximate value of y for x=x0+nh byMilnes method, we proceed as follows:
The value y0=y(x0) being given, we compute
y1=y(x0+h), y2=y(x0+2h), y3=(x0+3h),
By Picards or Tayolrs series method
Next we calculate,
8/7/2019 Applied Numerical Technique Lab Mannual
39/49
f0=f(x0,y0), f1=f(x0+h,y1), f2=f(x0+2h,y2), f3=f(x0+3h,y3)
Then to find y4=y(x0+4h), we substitute Newtons forward interpolation formula
f(x,y)=f0+nf0+ 2f0+ 3f0+.
In the relation
y4=y0+x0+4hx0 f(x,y) dx
y4=y0+x0+4hx0 (f0+nf0+ 2f0+ 3f0+.)dx [Put x=x0+nh,dx=hdn]
=y0+h 40 (f0+nf0+ 2f0+....)dn
=y0+h(4f0+8f0+ 2f0+ 3f0+.)
Neglecting fourth and higher order difference and expressing f0,2f0 and3f0 in terms of thefunction values, we get
y4=y0+4h(2f1-f2+2f3)/3
Which is called aspredictor
Having found y4, we obtain a first approximation to
f4=f(x0+4h,y4)
Then the better value of y4 is found by Simpsons rule as
y4=y2+h(f2+4f3+f4)/3
Which is called as corrector.
8/7/2019 Applied Numerical Technique Lab Mannual
40/49
PROGRAMMING IN C
#include
#include
#include
#define f(x,y) (x*y+y*y)
void main()
{
clrscr();
int n,i;
float x0,x1,x2,x3,y0,y1,y2,y3,y4,k4,x4,s,h,k1,k2,k3;
printf("Enter the value of x0\n");
scanf("%f",&x0);
printf("Enter the value of y0\n");
scanf("%f",&y0);
printf("Enter x1,x2,x3,x4\n");
scanf("%f %f %f %f",&x1,&x2,&x3,&x4);
printf("Enter the value of difference\n");
scanf("%f",&h);
printf("Enter the value of y1,y2,y3\n");
scanf("%f%f%f",&y1,&y2,&y3);
k1=f(x1,y1);
k2=f(x2,y2);
k3=f(x3,y3);
y4=y0+((4*h)*((2*k1)-k2+2*k3))/3;
8/7/2019 Applied Numerical Technique Lab Mannual
41/49
k4=f(x4,y4);
s=y2+((h/3)*(k2+4*k3+k4));
printf("The value of predictor is %f\n",y4);
printf("The value of corrector is %f\n",s);
getch();
}
8/7/2019 Applied Numerical Technique Lab Mannual
42/49
COMPUTER SOLUTION
Enter the value of x0
0
Enter the value of y0
1
Enter x1,x2,x3,x4
0.1
0.2
0.3
0.4
Enter the value of difference
0.1
Enter the value of y1,y2,y3
1.1169
1.2773
1.5049
The value of predictor1.835166
The value of corrector is1.839088
8/7/2019 Applied Numerical Technique Lab Mannual
43/49
EXPERIMENT 9
OBJECTIVE:Numerical solution of system of two ordinary differential equation using the
TRAPEZOIDAL RULE.TRAPEZOIDAL RULE
We have Newton-cotes quadrature formula i.e.
=nh[y0+ny0/2+n(2n-3)2y0/12+n(n-2)23y0+ 4y0/4!
+ 5y0/5!
+ 6y0/6! +..]
Now putting n=1 in this equation and taking the curve through (x0,y0) and (x1,y1) as a straight linei.e. a polynomial of first order so that difference of the order higher than first become zero, we get
=h(y0+y0/2)=h(y0+y1)2
Similarly =h(y1+y1/2)=h(y1+y2)2
=h(yn-1+yn-1/2)=h(yn-1+yn)2
Adding these n integrals, we obtain
=h[(y0+yn)+2(y1+y2++yn-1)]
This is known as the Trapezoidal rule
8/7/2019 Applied Numerical Technique Lab Mannual
44/49
8/7/2019 Applied Numerical Technique Lab Mannual
45/49
8/7/2019 Applied Numerical Technique Lab Mannual
46/49
8/7/2019 Applied Numerical Technique Lab Mannual
47/49
EXPERIMENT 10
OBJECTIVE:Numerical solution of system of two ordinary differential equation using the
SIMPSONS RULE.SIMPSONS RULE
We have Newton-cotes quadrature formula i.e.
=nh[y0+ny0/2+n(2n-3)2y0/12+n(n-2)23y0+ 4y0/4!
+ 5y0/5!
+ 6y0/6! +..]
Now putting n=2 in this equation and taking the curve through (x0,y0), (x1,y1) and (x2,y2) as aparabola i.e. a polynomial of second order so that difference of the order higher than secondbecome zero, we get
=2h(y0+y0+2y0/6)=h(y0+4y1+y2)/3
Similarly =h(y2+4y3+y4)/3
=h(yn-2+4yn-1+yn)/3, n being even
Adding these n integrals, we have when n is even
=h[(y0+yn)+4(y1+y3++yn-1)+2(y2+y4++yn-2)]/3
This is known as the Simpsons one third rule or simply Simpsons rule.
8/7/2019 Applied Numerical Technique Lab Mannual
48/49
PROGRAMMING IN C
#include
#include
#include
# define fn(x)(4*x+5*x*x)
void main()
{
clrscr();
float y,z,h,s,r;
int i,n;
printf("Enter initial value\n");
scanf("%f",&y);
printf("Enter last value\n");
scanf("%f",&z);
printf("Enter subintervals\n");
scanf("%d",&n);
h=(z-y)/n;
s=fn(y)+fn(z)+4*fn(y+h);
for(i=3;i
8/7/2019 Applied Numerical Technique Lab Mannual
49/49
COMPUTER SOLUTION
Enter initial value
0
Enter last value
1
Enter subintervals
10
The value of the integral=1.613333