Friday, April 27, 2018

Program Of bisection Method


# include <stdio.h>
# include <conio.h>
#include  < math.h>
# include <process.h>
#include <string.h>

# define EPS  0.00000005
# define  f(x)     x3 – x – 1
   void  Bisect ()
   int count  = 1 , n
   float root = 1;
  void main ()
  {
     clrscr (),
   priftf(“\n solution by Bisection method\n”);
    printf(“Equation”);
    printf(“\n\t\t\t x3 –x – 1 =0 \n\n”)
    printf(“Enter the no. of iteration:”);
    scanf(“%d”,&n);
    Bisect ();
    getch ();
 }
     void Bisect ()
 {
      float x0, x1, x2 ;
      float f0, f1, f2 ;
      int I =0 ;
     for (x2 = 1; x2++)
{
     f2  =  f(x2);
     if (f2 < 0);
     {
         Break ;
      }
}
     printf(“\n\t\t_ _ _ _ _ _ _ _ _ _ _ _ _”);
     printf(“\n\t\t   Root  = %  f ”,x0);
     printf(“\n\t\t  ITERATION = %d\n”, count -1 );
      printf(“\t\t_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ”);
      getch();
}

         Algorithm of Bisection Method
Step1:- Start of the program.
Step2:- I/P the various x1, x2, for the task.
Step3:- Check f(x1) * f(x2) < 0
Step4:- If yes proceed.
Step5:- If no exit & print error message.
Step6:- Repeat 7 – 11 if condition not satisfied.
Step7:-  x0= (x1 + x2)/2
Step8:- if f(x0) * f(x1) < 0
Step9:- x2 = x0
Step10:- ELSE
Step11:-   x1 = x0
Step12:-   Condition
Step13:- |(x1 – x2 ) /x1 | < max. possible error or f(x0) = 0.
Step14:-    printf o/p
Step15 :-   End of program.


No comments:

Post a Comment