Professional Documents
Culture Documents
Techniques And
Computing File
Submitted by:
VIJAY PUNIA
(7 ME 131-L)
INDEX
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
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θ
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
clrscr();
int i,n;
float h,y,x,x0,y0,t;
scanf("%d",&n);
scanf("%f",&x0);
scanf("%f",&y0);
scanf("%f",&h);
y=y0;
for(i=0;i<n;i++)
x=x0+i*h;
t=f(x,y);
y=y+h*t;
0.1
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)
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
clrscr();
int n,i;
float h,k,y,x,x0,y0,k1,k2,k3,k4;
scanf("%f",&x0);
scanf("%f",&y0);
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
0.2
x=0.2
y=1.2688
EXPERIMENT 8
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…..
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:
Next we calculate,
f0=f(x0,y0), f1=f(x0+h,y1), f2=f(x0+2h,y2), f3=f(x0+3h,y3)
In the relation
y4=y0+∫x0+4hx0 f(x,y) dx
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
f4=f(x0+4h,y4)
y4=y2+h(f2+4f3+f4)/3
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
clrscr();
int n,i;
float x0,x1,x2,x3,y0,y1,y2,y3,y4,k4,x4,s,h,k1,k2,k3;
scanf("%f",&x0);
scanf("%f",&y0);
printf("Enter x1,x2,x3,x4\n");
scanf("%f %f %f %f",&x1,&x2,&x3,&x4);
scanf("%f",&h);
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));
getch();
}
COMPUTER SOLUTION
Enter x1,x2,x3,x4
0.1
0.2
0.3
0.4
0.1
1.1169
1.2773
1.5049
TRAPEZOIDAL RULE
=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
=h[(y0+yn)+2(y1+y2+…+yn-1)]
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
clrscr();
float y,z,h,s,r;
int i,n;
scanf("%f",&y);
scanf("%f",&z);
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;
getch(); }
COMPUTER SOLUTION
SIMPSON’S RULE
=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[(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;
scanf("%f",&y);
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;
getch();}
COMPUTER SOLUTION
Enter subintervals
10