Logo 
Search:

C Programming Articles

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

Generalized program for Falsi Position Method

Posted By: Mina Schmidt     Category: C Programming     Views: 3270

Generalized program for Falsi Position Method.

Code for Generalized program for Falsi Position Method in C Programming

#include<stdio.h>
#include<conio.h>
#include<math.h>
#define E 0.001
void main()
{
    int ctr,temp,ctr1;

    float res,res1,prevX3;
    int p,NO;
    float X1=0.00,X2=0.00;
    float X3,FX1,FX2,FX3;
    int co[10];
    clrscr();

//Scanning Powers

    printf("\nEnter the Powers ::");
    flushall();
    scanf("%d",&p);
    NO=p;
//Storing Powers in arraysfor(ctr=p;ctr>=0;ctr--)
    {
        printf("\nCo-effiencent of %d::  ",ctr);
        scanf("%d",&co[ctr]);
    }

//For Scanning X1 and X2

    printf("\nEnter the Roots:1::");
    flushall();
    scanf("%f",&X1);

    printf("\nEnter the Roots:2::");
    flushall();
    scanf("%f",&X2);

//Greater than Zero rootsfor(ctr=p;ctr>=0;ctr--)
    {
        FX1  += co[ctr] * (pow(X1,ctr));
        FX2  += co[ctr] * (pow(X2,ctr));
    }
    if((FX1 * FX2)>0)
    {
        printf("\nThis is not Proper Approximation");

    }

    ctr1=0;
    clrscr();

    printf("\n==========================================================");
    printf("\nNO\tX1\tFX1\tX2\tFX2\tX3\tFX3");
    printf("\n==========================================================");

    do
    {

        prevX3=X3;

        X3 = ((X1*FX2) - (X2*FX1)) / (FX2 - FX1);

        FX1=FX2=FX3=0.0;

        for(ctr=p;ctr>=0;ctr--)
        {
            FX3  += co[ctr] * (pow(X3,ctr));
            FX1  += co[ctr] * (pow(X1,ctr));
            FX2  += co[ctr] * (pow(X2,ctr));
        }
        printf("\n%d\t%.4f\t%.4f\t%.4f\t%.4f\t%.4f\t%.4f",ctr1+1,X1,FX1,X2,FX2,X3,FX3);

        if((FX1 * FX3)>0)
        {
            X1=X3;

        }
        elseif(FX3 == 0)
        {
            printf("%.4f",X3);
            break;
        }
        else
        {
            X2=X3;

        }

        ctr1++;
    }
    while(fabs(prevX3-X3)>E);
    printf("\n\n\tThe Root:: %.4f",X3);

    getch();
}
  
Share: 

 
 
 

Didn't find what you were looking for? Find more on Generalized program for Falsi Position Method Or get search suggestion and latest updates.

Mina Schmidt
Mina Schmidt author of Generalized program for Falsi Position Method is from Frankfurt, Germany.
 
View All Articles

 
Please enter your Comment

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

 
No Comment Found, Be the First to post comment!