Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Numerical MethodsRSS Feeds

Program of BAIRSTOW'S METHOD

Posted By: Lucas Silva     Category: C Programming     Views: 8155

Write a program of BAIRSTOW'S METHOD.

Code for Program of BAIRSTOW'S METHOD in C Programming

#include<stdio.h>
#include<conio.h>
#include<math.h>
#define ESP 0.001
#define F(x) (x)*(x)*(x) + (x) + 10
#define a3 1
#define a2 0
#define a1 1
#define a0 10
//#define c3  0void main()
{
  double u,v,u1,v1,u2,v2,b3,b2,p,b1,b0,c2,c1,c0,U,V;
  int i=1;
  float c3=0;
  clrscr();
  printf("\nEnter the value of u: ");
  scanf("%lf",&u);
  printf("\nEnter the value of v: ");
  scanf("%lf",&v);
  b3=a3;
  b2=a2+u*b3;
  b1=a1+u*b2+v*b3;
  b0=a0+u*b1+v*b2;
  c2=b3;
  c1=b2+u*c2+v*c3;
  c0=b1+u*c1+v*c2;
  p=c1*c1-c0*c2;
  U=((-(b1*c1-b0*c2))/(p));
  V=((-(b0*c1-c0*b1))/(p));
  u1=u+U;
  v1=v+V;
  printf("\n\n b0 = %lf",b0);
  printf("\n\n b1 = %lf",b1);
  printf("\n\n b2 = %lf",b2);
  printf("\n\n b3 = %lf",b3);
  printf("\n\n c0 = %lf",c0);
  printf("\n\n c1 = %lf",c1);
  printf("\n\n c2 = %lf",c2);
  printf("\n\n c3 = %lf",c3);
  printf("\n\n * * * u = %lf * * *",u1);
  printf("\n\n * * * v = %lf * * *",v1);

  do
  {
   u=u1;
   v=v1;
   b3=a3;
   b2=a2+u*b3;
   b1=a1+u*b2+v*b3;
   b0=a0+u*b1+v*b2;
   c2=b3;
   c1=b2+u*c2+v*c3;
   c0=b1+u*c1+v*c2;
   p=c1*c1-c0*c2;
   U=((-(b1*c1-b0*c2))/(p));
   V=((-(b0*c1-c0*b1))/(p));
   u2=u+U;
   v2=v+V;
   printf("\n\n b0 = %lf",b0);
   printf("\n\n b1 = %lf",b1);
   printf("\n\n b2 = %lf",b2);
   printf("\n\n b3 = %lf",b3);
   printf("\n\n c0 = %lf",c0);
   printf("\n\n c1 = %lf",c1);
   printf("\n\n c2 = %lf",c2);
   printf("\n\n c3 = %lf",c3);
   printf("\n\n  u = %lf ",u2);
   printf("\n\n  v = %lf ",v2);

   if(fabs(u1 - u2) < ESP && fabs(v1-v2) < ESP)
   {
    printf("\n\nREAL ROOT = %.3lf",u2);
    printf("\n\nREAL ROOT = %.3lf",v2);
    i=0;
   }
   else
   {
     u1 = u2;
     v1 = v2;
   }
  }while(i!=0);
getch();
}

/*
____________________________

OUT PUT
____________________________

Enter the value of u: 1.8
Enter the value of v: -4

b0 = 3.232000

b1 = 0.240000

b2 = 1.800000

b3 = 1.000000

c0 = 2.720000

c1 = 3.600000

c2 = 1.000000

c3 = 0.000000

u = 2.031250

v = -5.072500

b0 = -0.194891

b1 = 0.053477

b2 = 2.031250

b3 = 1.000000

c0 = 3.656953

c1 = 4.271250

c2 = 1.000000

c3 = 0.000000

u = 2.002230

v = -5.002025

b0 = -0.001389

b1 = 0.006900

b2 = 2.002230

b3 = 1.000000

c0 = 6.121717

c1 = 5.552230

c2 = 1.000000

c3 = 0.000000

u = 2.000623

v = -5.000003

b0 = 0.001859

b1 = 0.002490

b2 = 2.000623

b3 = 1.000000

c0 = 11.224619

c1 = 8.108540

c2 = 1.000000

c3 = 0.000000

u = 2.000287

v = -4.999767

REAL ROOT = 2.000

REAL ROOT = -5.000

*/
  
Share: 


Didn't find what you were looking for? Find more on Program of BAIRSTOW'S METHOD Or get search suggestion and latest updates.

Lucas  Silva
Lucas Silva author of Program of BAIRSTOW'S METHOD is from Salvador, Brazil.
 
View All Articles

 

Other Interesting Articles in C Programming:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
Billy Braga from Canada Comment on: Mar 27
* for n = 3

your polynom should be an array

Billy Braga from Canada Comment on: Mar 27
DUDE... CRAP CODE !!! Why did you program pour n = 3 !!??!?

View All Comments