Sunday, June 12, 2016

REGULA FALSI METHOD


Regula Falsi method is also called false position method which is used for finding the root of the equation. As in bisection method, we start with two initial guesses in this method too and reduced exact root using the formula,

x3 = {x1f(x2) - x2f(x1)}  /  {f(x2) - f(x1)}

In general,
x0= {af(b) - bf(a)}  /  {f(b) - f(a)}

Program Code Implemented in C


#include<stdio.h>
#include<math.h>
#define f(x) x*x-17*x+65
#include<conio.h>
#define err 0.001

void main()
{
clrscr();
    float a,b,x;
    float fa,fb,fx;


    do{
    printf("Enter two initial guesses\t");
    scanf("%f%f",&a,&b);
    fa=f(a);
    fb=f(b);

    }while((fa*fb)>0);
    printf("\t  a\t      b\t        f(a)\t    f(b)\t  x\t    f(x)\n\n");

    do{
              x=(a*fb-b*fa)/(fb-fa);
printf("\t%f   %f   %f   %f   %f   %f\n\n",a,b,fa,fb,x,fx);
              fx=f(x);
              fa=f(a);
              fb=f(b);
              if((fb*fx)<0)
                 {
                      a=x;
                 }
                 else
                   b=x;


    }while(fabs(a-b)>err);

          printf("Root is %f",x);
          getch();
}


Sample Output


Here the equation x*x-17*x+65 is taken as reference. So the solution of this equation gives the value of x=5.781 and 11.19 as the solutions so our guess is in between them. In first compiling we guess 4 and 6 as a root so the output is 5.81 which is in between 4 and 6. Similarly in second attempt we guess 11 and 13 hence the output is 11.19 which are shown below:









Note: This method is similar as bisection method but we reduce the steps to find exact root by using the formula.

No comments:

Post a Comment