You are on page 1of 2

BISECTION.

C Euler’s Method
#include<stdio.h> #include<stdio.h>
#include<conio.h> #include<conio.h>
#include<math.h> #include<math.h>
void main() void main()
{ {
int i=1; float i,x,y,h,fx,n;
float x1,x2,x3,fx1,fx2,fx3,temp; clrscr();
clrscr(); printf("Enter the values of x,y,h,n ");
xyz:printf("Enter 2 values in the range of the root "); scanf("%f %f %f %f",&x,&y,&h,&n);
scanf("%f %f",&x1,&x2); while(x<n)
fx1=pow(x1,3)-2*x1-5; {
fx2=pow(x2,3)-2*x2-5; fx=y+h*(x-y*y);
printf("Sr.No x1 x2 x3 fx3\n"); printf("\nx=%f y=%f h=%f fx=%f",x,y,h,fx);
if(fx1*fx2<0) x=x+h;
{ y=fx;
do }
{ printf("\nfx=%f",fx);
temp=x3; getch();
x3=(x1+x2)/2; }
fx3=pow(x3,3)-2*x3-5; Euler’s Modified Method
printf("\n%5d %9f %9f %9f %9f",i,x1,x2,x3,fx3); #include<stdio.h>
if(fx1*fx3<0) #include<conio.h>
x2=x3; #include<math.h>
else void main()
x1=x3; {
i++; float x0,y0,h,fx,x1,y1,y1n,y1n1,temp;
getch(); clrscr();
}while(temp!=x3); printf("Enter the values of x0 & y0 ");
printf("\n\nThe root of the equation by Bisection Method is scanf("%f %f",&x0,&y0);
%f",x3); printf("Enter h: ");
} scanf("%f",&h);
else fx=x0+3*y0;
{ printf("fx=%f\n",fx);
printf("Values not in the range, enter different values\n"); y1=y0+h*fx;
goto xyz; printf("Enter x1 ");
} scanf("%f",&x1);
getch(); y1n=y1;
} printf("y1n=%f",y1n);
False Position Method y1n1=y0+(h/2)*(fx+(x1+3*y1n));
#include<stdio.h> printf("\ty1n1=%f",y1n1);
#include<conio.h> do
#include<math.h> {
void main() temp=y1n1;
{ y1n1=y0+(h/2)*(fx+(x1+3*y1n1));
int i=1; printf("\ny1n+1=%f",y1n1);
float x0,x1,x2,fx1,fx2,fx0,temp; }while(temp!=y1n1);
clrscr(); printf("\n\ny(%f)=%f",x1,y1n1);
xyz:printf("\nEnter 2 values in the range of the root "); getch();
scanf("%f %f",&x0,&x1); }
fx0=pow(x0,3)-2*x0-5; Newton Rapsons Method
fx1=pow(x1,3)-2*x1-5; #include<stdio.h>
//printf("Enter the number of iterations "); #include<conio.h>
//scanf("%d",&n); #include<math.h>
if(fx0*fx1<0) void main()
{ {
printf("Sr.No x0 x1 x2 fx2\n"); int i=1;
do float x0,x1,fx0,fx1,f1x0,temp;
{ clrscr();
temp=x2; printf("\nEnter initial values in the range of the root ");
x2=x0-(((x1-x0)*fx0)/(fx1-fx0)); scanf("%f",&x0);
fx2=pow(x2,3)-2*x2-5; fx0=pow(x0,3)-2*x0-5;
printf("\n%5d %9f %9f %9f %9f",i,x0,x1,x2,fx2); f1x0=3*pow(x0,2)-2;
if(fx0*fx2>0) printf("Sr.No x0 fx0 f1x0 x2\n");
x0=x2; do
else {
x1=x2; temp=x1;
i++; x1=x0-(fx0/f1x0);
getch(); printf("\n%5d %10f %10f %10f %10f",i,x0,fx0,f1x0,x1);
}while(temp!=x2); x0=x1;
printf("\nThe root of the equation by False Position Method fx0=pow(x0,3)-2*x0-5;
is %f",x2); f1x0=3*pow(x0,2)-2;
} i++;
else getch();
{ }while(temp!=x1);
printf("Enter value in different range\n"); printf("\nThe root of the equation by Newton Raphson
goto xyz; Method is %f",x1);
} getch();
getch(); }
}
Gauss Elimination
#include<stdio.h>
#include<conio.h> printf("\nThe value of Numerical Integration by Trapezoidal
#include<math.h> rule is = %f",I);
void main() getch();
{ }
float x,y,z,x1,y1,z1,x2,y2,z2; Simpsons 1/3 Rule
clrscr(); #include<stdio.h>
printf("The 3 equations are:\n"); #include<conio.h>
printf("10x+y+z=12\n"); #include<math.h>
printf("2x+10y+z=13\n"); #define e 2.72
printf("2x+2y+10z=14\n"); void main()
x=0; {
y=0; float y[10],I,J,K,L;
z=0; int i,a,b,h,n;
while(x2!=x1 && y2!=y1 && z2!=z1) clrscr();
{ printf("Enter the values of a,b,n: ");
x2=x1; scanf("%d %d %d",&a,&b,&n);
x1=(12-y-z)/10; h=(b-a)/n;
x=x1; printf("h=%d",h);
y2=y1; for(i=a;i<=b;i=i+h)
y1=(13-2*x-z)/10; {
y=y1; y[i]=pow(e,i);
z2=z1; printf("\ny[%d]=%f",i,y[i]);
z1=(14-2*x-2*y)/10; }
z=z1; J=0;
printf("\nx=%f y=%f z=%f",x1,y1,z1); for(i=a+h;i<=b-h;i=i+h+h)
} {
getch(); J=J+y[i];
} }
L=0;
Ringe-Kutta Method for(i=a+h+h;i<=b-h-h;i=i+h+h)
#include<stdio.h> {
#include<conio.h> L=L+y[i];
void main() }
{ K=(y[a]+y[b]+4*J+2*L);
float x0,y0,x,y,x1,y1,K1,K2,h; I=K*h/3;
clrscr(); printf("\nThe value of Numerical Integration by Simpson's
printf("Enter the intial values of x & y "); 1/3rd rule is = %f",I);
scanf("%f %f",&x0,&y0); getch();
printf("Enter the value of h "); }
scanf("%f",&h); Simpsons 3/8 Rule
printf("Enter the final value of x "); #include<stdio.h>
scanf("%f",&x1); #include<conio.h>
do #include<math.h>
{ #define e 2.72
K1=h*(y0-x0); void main()
x=x0+h; {
y=y0+K1; float y[10],I,J,K,L;
K2=h*(y-x); int i,a,b,h,n;
y1=y0+((K1+K2)/2); clrscr();
printf("\ny(%f)=%f",x,y1); printf("Enter the values of a,b,n: ");
x0=x; scanf("%d %d %d",&a,&b,&n);
y0=y1; h=(b-a)/n;
}while(x0!=x1); printf("h=%d",h);
getch(); for(i=a;i<=b;i=i+h)
} {
y[i]=1/pow(1+i,2);
Trapezoidal Method printf("\ny[%d]=%f",i,y[i]);
#include<stdio.h> }
#include<conio.h> J=0;
#include<math.h> L=0;
#define e 2.72 for(i=a+h;i<=b-h;i=i+h)
void main() {
{ if(i%3==0)
float y[10],I,J,K; {
int i,a,b,h,n; L=L+y[i];
clrscr(); }
printf("Enter the values of a,b,n: "); else
scanf("%d %d %d",&a,&b,&n); {
h=(b-a)/n; J=J+y[i];
printf("h=%d",h); }
for(i=a;i<=b;i=i+h) }
{ K=(y[a]+y[b]+3*J+2*L);
y[i]=pow(e,i); I=K*3*h/8;
printf("\ny[%d]=%f",i,y[i]); printf("\nThe value of the Numerical Intergral by Simpson's
} 3/8th rule is = %f",I);getch();
J=0; }
for(i=a+h;i<=b-h;i=i+h)
{
J=J+y[i];
}
K=(y[a]+y[b]+2*J);
I=K*h/2;