By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,897 Members | 1,969 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,897 IT Pros & Developers. It's quick & easy.

c programming

P: 21
c program for bisection method to find roots of a polynomial
Oct 4 '06 #1
Share this Question
Share on Google+
2 Replies


P: 9
/* x
/*The Bisection Method to solve cosx-xe ***********/
#include<stdio.h>
#include<conio.h>
#include<math.h>
float c(float x );
float f(float x);
main()
{

float a,b,y,r1,r2,r3;
do{
printf("\nenter approximate interval");
scanf("%f%f",&a,&b);
r1=f(a);
r2=f(b);
}while(r1*r2>0);
printf("a\t\tb x=(a+b)/2 f(x)\n\n");
do{
r1=f(a);
r2=f(b);
y= (a+b)/2.0;
r3=f(y);
printf( "%.4f %.4f %.4f %.4f",a,b,y,r3);
if(r1*r3<0)
b=y;
else
a=y;
printf("\n");
}while(fabs(r3)>0.0001);
printf("\n The approx sol is %f",y);
getch();
return 0;
}
float c(float x)
{
float rad;
rad=((3.1416)/180.0) *x;
return(cos(rad));
}
float f(float x )
{
float f1;
f1=c(x)-(x*pow(2.7183,x));
return(f1);
}

you can change the function f to solve some other polynomial.
Oct 4 '06 #2

100+
P: 293
D_C
There is a similar thread here. Unfortunately I don't think anyone ever came up with a working answer in that thread.
Oct 4 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.