c programming

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sekitoleko
    New Member
    • Sep 2006
    • 21

    c programming

    c program for bisection method to find roots of a polynomial
  • priya mahajan
    New Member
    • Sep 2006
    • 9

    #2
    /* 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.

    Comment

    • D_C
      Contributor
      • Jun 2006
      • 293

      #3
      There is a similar thread here. Unfortunately I don't think anyone ever came up with a working answer in that thread.

      Comment

      Working...