You are on page 1of 49

Applied Numerical

Techniques And
Computing File

Submitted by:
VIJAY PUNIA
(7 ME 131-L)

INDEX

SNO. OBJECTIVE DATE SIGN REMARK

Solution of non linear equation


1 in single variable using the 11/AUG/0
method of SUCCESSIVE 9
BISECTION.
Solution of non linear equation
2 in single variable using the 18/AUG/0
NEWTON RAPHSON METHOD. 9
Solution of a system of
3 simultaneous algebraic 25/AUG/0
equations using the GUASSIAN 9
ELIMINATION PROCEDURE.
Solution of a system of
4 simultaneous algebraic 01/SEP/0
equations using the GUASS 9
JORDAN PROCEDURE.
Solution of a system of
5 simultaneous algebraic 08/SEP/0
equations using the GUASS 9
SEIDAL ITERATIVE METHOD.
Numerical solution of an
6 ordinary differential equation 15/SEP/0
using the EULER’S METHOD. 9
Numerical solution of an
7 ordinary differential equation 22/SEP/0
using the RUNGE – KUTTA 4TH 9
ORDER METHOD.
Numerical solution of an
8 ordinary differential equation 29/SEP/0
using the PREDICTOR– 9
CORRECTOR METHOD.
Numerical solution of system
9 of two ordinary differential 6/OCT/09
equation using the
TRAPEZOIDAL RULE
Numerical solution of system
10 of two ordinary differential 27/OCT/0
equation using the SIMPSON’S 9
RULE

EXPERIMENT -1
OBECTIVE:- Solution of non linear equation in single variable using method of successive
BISECTION.
BISECTION METHOD
This method is based on the repeated application of the intermediate value property. Let the
function f(x) be continuous between a and b. for the definiteness, let f(a)be negative and f(b) be
positive . 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 b
according as f(x1) is positive or negative. Then we bisect the interval as before and continue the
process until the root is found to desired accuracy.
In the fig. 1, f(x1) is positive, so that the root lies between a and x1. Then the second approximation
to the root root is x2=(a+x1)/2. If f(x2) is –ve, the root lies between x1 and x2. Then third
approximation to he root is x3=(x1+x2)/2 and so on.
FIG. 1
FLOW CHART
PROGRAME IN C
#include<stdio.h>
#include<conio.h>
#include<math.h>
# 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);
if(y1*y<0)
{
b=x;
}
else
{
a=x;
}
printf("no. of iterrations i=\t%d\n",i);
i=i++;
printf("approx root of the equation is x=\t%f\n",x);
}
while(fabs(b-a)>eps);
}
getch();
}

COMPUTER SOLUTION
Enter the value of a =2
Enter the value of b =3
Enter the value of eps = .0001
No. of iterations i=1
Approx 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
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
EXPERIMENT – 2
OBJECTIVE:- Solution of non linear equation in single variable using NEWTON RAPHSON
method.
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 tayolor’s 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))
FLOW CHART
PROGRAMING IN C
#include<stdio.h>
#include<conio.h>
#include<math.h>
#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<=n;i++)
{
h=f(x0)/df(x0);
x1=x0-h;
error=x1-x0;
x0=x1;
printf("the no of iterration %d\n",i);
printf("the approx root are x = %f\n",x0);
}
getch();}
COMPUTER SOLUTION
Enter the value of x0 and eps
1
.00001
Enter 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
EXPERIMENT – 3

OBJECTIVE:- Solution of a system of simultaneous algebraic equations using the GUASSIAN


ELIMINATION PROCEDURE.
GUASSIAN ELIMINATION
In this method, the unknowns are eliminated successively and the system is reduced to an upper
triangular system from which the unknown are found by back substitution. The method is quite
general and is well adapted computer operations. 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
b2’y+c2’z=d2’
b3’y+c3’z=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’) times
the second equation from third equation. We thus, get the new system
a1x+b1y+c1z=d1
b2’y+c2’z=d2’
c3’’z=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.
FLOW CHART
PROGRAMING IN C
#include<stdio.h>
#include<conio.h>
#include<math.h>
#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<n;i++)
for(j=0;j<n+1;j++)
scanf("%f",&a[n][n+1]);
for(j=0;j<n-1;j++)
{
for(i=j+1;i<n;i++)
{
t=a[i][j]/a[j][j];
for(k=0;k<n+1;k++)
{
a[i][k]=a[j][k]*t;
}
}
}
//nw printing the upper triangular matrix
printf("the upper triangular matrix is\n");
for(i=0;i<n;i++)
{
for(j=0;j<n+1;j++)
{
printf("%f\t",a[i][j]);
}
printf("\n");
}
//now back subsitution
for(i=n-1;i>=0;i--)
{
s=0;
for(j=i+1;j<n;j++)
{
s=s+(a[i][j]*x[j]);
}
x[i]=(a[i][n]-s)/a[i][i];
}
//printing the result
printf("the solution is\n");
for(i=0;i<n;i++)
{
printf("x[%d]=%f\n",i+1,x[i]);
}
getch();
}
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 -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
EXPERIMENT – 4

OBJECTIVE:- Solution of a system of simultaneous algebraic equations using the GUASS


JORDAN PROCEDURE.
GAUSS JORDAN
This is modification of gauss elimination method. In this method, elimination of unknowns is
performed not in the equation below but also in the equation above, ultimately reducing the system
in diagonal matrix form i.e. each equation involving only one unknown. From these equations the
unknowns x, y, z xan be obtained readily.
Thus in this method, the labour of back substitution for finding the unknowns is saved at
the 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
b2’y+c2’z=d2’
b3’y+c3’z=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
a1’x+ c1’z=d1’
b2’y+c2’z=d2’
c3’z=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
a1’’x =d1’’
b2’’y =d2’’
c3’’z=d3’’ …….3
FLOW CHART
PROGRAMING IN C
#include<stdio.h>
#include<conio.h>
#include<math.h>
#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<n;i++)
{
for(j=0;j<n+1;j++)
{
scanf("%f",&a[n][n+1]);
}
}
//now calculating the values of x1,x2,.......,xN
for(j=0;j<n-1;j++)
{
for(i=j+1;i<n;i++)
{
if(i!=j)
{
t=a[i][j]/a[j][j];
for(k=0;k<n+1;k++)
{
a[i][k]=a[j][k]*t;
}
}
}
}
//nw printing the upper triangular matrix
printf("the diagonal matrix is:-\n");
for(i=0;i<n;i++)
{
for(j=0;j<n+1;j++)
{
printf("%f\t",a[i][j]);
}
printf("\n");
}
//printing the result
printf("the solution is:-\n");
for(i=0;i<n;i++)
{
printf("x[%d]=%f\n",i+1,x[i][n]/a[i][i]);
}
getch();
}
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
EXPERIMENT – 5

OBJECTIVE:- Solution of a system of simultaneous algebraic equations using the GUASS


SEIDAL ITERATIVE METHOD.
GUASS SEIDAL ITERATIVE METHOD
The preceding methods of solving simultaneous linear equation are known as direct methods, as
these methods yield the solution after a certain amount of fixed computation. On the other hand, an
iterative method is that in which we start from an approximation to the true solution and obtain
better and better approximations from a computation cycle repeated as often as may be necessary
for 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 each
be 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 in
the next step.
This process of iteration is repeated till the values of x, y, z are obtained to desire degree of
accuracy.
FLOW CHART
PROGRAMING IN C
#include<stdio.h>
#include<conio.h>
#include<math.h>
#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<n;i++)
x[i]=0;
printf("enter the agumented matrix rowwise\n");
for(i=0;i<n;i++)
{
for(j=0;j<n+1;j++)
{
scanf("%f",&a[n][n+1]);
}
}
printf("Enter the allowed error,maximum iteration\n");
scanf("%f %d",&aerr,&matrix);
printf("iteration\tx[1]\tx[2]\t[3]\n");
for(itr=1;itr<=matrix;itr++)
{maxerr=0;
for(i=0;i<n;i++)
{
s=0;
for(j=0;j<n;j++)
if(j!=i)
s+=a[i][j]*x[j];
t=(a[i][n]-s)/a[i][i];
err=fabs(x[i]-t);
if(err>maxerr)
maxerr=err;
x[i]=t;
}
printf(("%d",itr);
for(i=0;i<n;i++)
printf("%f",x[i]);
printf("\n");
if(maxerr<err)
{
printf("converges in %d iteration\n",itr);
for(i=0;i<n;i++)
printf("x[%d]=%f\n",i+1,x[i]);
}
}
printf("solution does not converges iterations not sufficient");
getch();
}
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
EXPERIMENT - 6
OBJECTIVE : Numerical solution of an ordinary differential equation using the EULER’S
METHOD.
EULER’S METHOD.

Consider the equation ……(1)


Given that y(x0)=y0. It’s a curve of solution through p(x0,y0) is shown in figure. Now we have to
find 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 this
tangent 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 ordinate
through 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 Euler’s method of finding an approximate solution of (1)
FLOW CHART
PROGRAMING IN C

#include<stdio.h>

#include<conio.h>

#include<math.h>

#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<n;i++)

x=x0+i*h;

t=f(x,y);

y=y+h*t;

printf("the no of iteration i=%d The value of y=%f\n",i,y); } getch();


COMPUTER SOLUTION

Enter the number of iteration

Enter the value of x0

Enter the value of y0

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


EXPERIMENT 7
OBJECTIVE: Numerical solution of an ordinary differential equation using the RUNGE –
KUTTA 4TH ORDER METHOD.
RUNGE – KUTTA METHOD.
The Taylor’s series method of solving differential equations numerically is restricted by the
labour involved in finding the higher order derivatives . however there is class of methods known
as Runge-Kutta methods which do not require the calculations of higher order derivatives and give
greater accuracy . The Runge-Kutta formulae possess the advantage of requiring only the function
values at some selected points. These methods agree with Taylor’s series solution upto the term in
hr 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= +(k1+2k2+2k3+k4)

Which gives the required approximate value as y1=y0+k.


FLOW CHART
PROGRAMMING IN C

#include<stdio.h>

#include<conio.h>

#include<math.h>

#define f(x,y) (x+y*y)

void main()

clrscr();

int n,i;

float h,k,y,x,x0,y0,k1,k2,k3,k4;

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);

k1=h*(f(x0,y0));

k2=h*(f(x0+(h/2),y0+(k1/2)));

k3=h*(f(x0+(h/2),y0+(k2/2)));

k4=h*(f(x0+h,y0+k3));

k=(k1+(2*k2)+(2*k3)+k4)/6;

x=x0+h;

y=y0+k;

printf("x=%f \t y=%f",x,y);

getch();}
COMPUTER SOLUTION

Enter the value of x0

Enter the value of y0

Enter the value of h

0.2

x=0.2

y=1.2688
EXPERIMENT 8

OBJECTIVE: Numerical solution of an ordinary differential equation using the PREDICTOR–


CORRECTOR METHOD.

PREDICTOR–CORRECTOR METHOD.

If xi-1 and xi be the two consecutive mesh points we have xi =xi-1+h. In the Euler’s method
we have

yi=yi-1+hf(x0+Ei-1h,yi-1);i=1,2,3…..

The modified Euler’s 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 yi agree. This
technique 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 as
a corrector of yi.

In this method so far described to solve a differential equation over an interval, only the
value of y at the beginning of the interval was required. In the predictor-corrector methods, four
prior values are needed for finding the value of y at x i. Though slightly complex these methods
have the advantage of giving an estimate of error from successive approximations to yi.

We have two such methods, namely : Milne’s method and Admas-Bashforth method.

MILNE’S METHOD

Given dy/dx=f(x,y) and y=y0, x=x0; to find an approximate value of y for x=x0+nh by
Milne’s 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 Picard’s or Tayolr’s series method

Next we calculate,
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 Newton’s forward interpolation formula

f(x,y)=f0+nΔf0+ Δ2f0+ Δ3f0+……….

In the relation

y4=y0+∫x0+4hx0 f(x,y) dx

y4=y0+∫x0+4hx0 (f0+nΔf0+ Δ2f0+ Δ3f0+……….)dx [Put x=x0+nh,


dx=hdn]

=y0+h∫ 40 (f0+nΔf0+ Δ2f0+…....)dn

=y0+h(4f0+8Δf0+ Δ2f0+ Δ3f0+….)

Neglecting fourth and higher order difference and expressing Δf0,Δ2f0 andΔ3f0 in terms of the
function values, we get

y4=y0+4h(2f1-f2+2f3)/3

Which is called as predictor

Having found y4, we obtain a first approximation to

f4=f(x0+4h,y4)

Then the better value of y4 is found by Simpson’s rule as

y4=y2+h(f2+4f3+f4)/3

Which is called as corrector.


PROGRAMMING IN C

#include<stdio.h>

#include<conio.h>

#include<math.h>

#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;
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();

}
COMPUTER SOLUTION

Enter the value of x0

Enter the value of y0

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


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+nΔy0/2+n(2n-3)Δ2y0/12+n(n-2)2Δ3y0+ Δ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 line
i.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


PROGRAMMING IN C

#include<stdio.h>

#include<conio.h>

#include<math.h>

# define fn(x) (4*x-3*x*x)

void main()

clrscr();

float y,z,h,s,r;

int i,n;

printf("Enter the initial value\n");

scanf("%f",&y);

printf("Enter the last value\n");

scanf("%f",&z);

printf("Enter the subintervals\n");

scanf("%d",&n);

h=(z-y)/n;

s=fn(y)+fn(z);

for(i=0;i<n;i++)

s=s+2*fn(y+i*h);

r=(h/2)*s;

printf("The result of integration=%f\n",r);

getch(); }
COMPUTER SOLUTION

Enter the initial value:0

Enter the last value:1

Enter the subintervals:10

The result of integration=0.995


EXPERIMENT 10

OBJECTIVE:Numerical solution of system of two ordinary differential equation using the


SIMPSON’S RULE.

SIMPSON’S RULE

We have Newton-cotes quadrature formula i.e.

=nh[y0+nΔy0/2+n(2n-3)Δ2y0/12+n(n-2)2Δ3y0+ Δ4y0/4!

+ Δ5y0/5!

+ Δ6y0/6! +………..]

Now putting n=2 in this equation and taking the curve through (x 0,y0), (x1,y1) and (x2,y2) as a
parabola i.e. a polynomial of second order so that difference of the order higher than second
become 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 Simpson’s one third rule or simply Simpson’s rule.
PROGRAMMING IN C

#include<stdio.h>

#include<conio.h>

#include<math.h>

# 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<n;i+=2)

s=s+4*(y+i*h)+2*fn(y+(i-1)*h);

r=(h/3)*s;

printf("The value of the integral=%f\n",r);

getch();}
COMPUTER SOLUTION

Enter initial value

Enter last value

Enter subintervals

10

The value of the integral=1.613333

You might also like