Program of BISECTION METHOD in C Language


#include
#include
#include
#define ESP 0.001
#define F(x) (x)*(x)*(x) + (x)*(x) + (x) + 7
void main()
{
int i = 1;
float x0,x1,x2;
double f1,f2,f0,t;
clrscr();
printf("\nEnter the value of x0: ");
scanf("%f",&x0);

printf("\nEnter the value of x1: ");
scanf("%f",&x1);
printf("\n__________________________________________________________________\n");
printf("\niteration\t x0\t x1\t x2\t f0\t f1\t f2");
printf("\n___________________________________________________________________\n");
do
{
x2=(x0+x1)/2;
f0=F(x0);
f1=F(x1);
f2=F(x2);
printf("\n%d %f %f %f %lf %lf %lf", i, x0,x1,x2,f0,f1,f2);
if(f0*f2<0)
{
x1=x2;
}
else
{
x0=x2;
}
i++;
}while(fabs(f2)>ESP);
printf("\n__________________________________________________________\n");
printf("\n\nApp.root = %f",x2);
getch();
}




OUTPUT :


Enter the value of x0: -2

Enter the value of x0: -1

Enter the value of x1: -2

__________________________________________________________

x0 x1 x2 f0 f1 f2
__________________________________________________________

-1.000000 -2.000000 -1.500000 -5.000000 2.000000 -1.750000
-1.500000 -2.000000 -1.750000 -1.750000 2.000000 0.062500
-1.500000 -1.750000 -1.625000 -1.750000 0.062500 -0.859375
-1.625000 -1.750000 -1.687500 -0.859375 0.062500 -0.402344
-1.687500 -1.750000 -1.718750 -0.402344 0.062500 -0.170898
-1.718750 -1.750000 -1.734375 -0.170898 0.062500 -0.054443
-1.734375 -1.750000 -1.742188 -0.054443 0.062500 0.003967
-1.734375 -1.742188 -1.738281 -0.054443 0.003967 -0.025253
-1.738281 -1.742188 -1.740234 -0.025253 0.003967 -0.010647
-1.740234 -1.742188 -1.741211 -0.010647 0.003967 -0.003341
-1.741211 -1.742188 -1.741699 -0.003341 0.003967 0.000313
__________________________________________________________


App.root = -1.741699

Related Links :

No comments:

Post a Comment


If you face any Problem in viewing code such as Incomplete "For Loops" or "Incorrect greater than or smaller" than equal to signs then please collect from My Web Site CLICK HERE


More Useful Topics...

 

History Of C..

In the beginning was Charles Babbage and his Analytical Engine, a machine
he built in 1822 that could be programmed to carry out different computations.
Move forward more than 100 years, where the U.S. government in
1942 used concepts from Babbage’s engine to create the ENIAC, the first
modern computer.
Meanwhile, over at the AT&T Bell Labs, in 1972 Dennis Ritchie was working
with two languages: B (for Bell) and BCPL (Basic Combined Programming
Language). Inspired by Pascal, Mr. Ritchie developed the C programming
language.

My 1st Program...


#include
#include
void main ()
{
clrscr ();
printf ("\n\n\n\n");
printf ("\t\t\t*******Pankaj *******\n");
printf ("\t\t\t********************************\n");
printf ("\t\t\t\"Life is Good...\"\n");
printf ("\t\t\t********************************");
getch ();
}

Next Step...


#include
#include

void main ()
{
clrscr ();
printf ("\n\n\n\n\n\n\n\n");
printf ("\t\t\t --------------------------- \n\n");

printf ("\t\t\t | IGCT, Info Computers, INDIA | \n\n");
printf ("\t\t\t --------------------------- ");

getch ();

}

Hits!!!