Logo 
Search:

C Programming Articles

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

BISECTION METHOD FOR PARTICULAR

Posted By: Adelbert Fischer     Category: C Programming     Views: 5541

Write a program of BISECTION METHOD FOR PARTICULAR.

Code for BISECTION METHOD FOR PARTICULAR in C Programming

#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int i=0,cnt=0,flag=0;
float x1,x2,x3=0;
float fx1=0,fx2=0,fx3=0,t=0;



float func(float f)
{
    return(log10(f)-cos(f));
}

int check()
{
    printf("\n\tINTIAL X1---->");
    scanf("%f",&x1);

    printf("\n\tINTIAL X2---->");
    scanf("%f",&x2);

    fx1=fx2=fx3=0.0;


    if( (func(x1)*func(x2))>0)
    {
        printf("\n\t INTIAL VALUES ARE NOT PERFECT.");
        return(1);
    }
    return(0);
}
void main()
{
    clrscr();


    printf("\n\n\t\t\t PROGRAM FOR PARICULAR BISECTION GENERAL");
    printf("\n\n\t EQUATION ::::: LOG(X)-COS(X)");

    while(1)
    {
        if(check()==0)
        {
            flag=1;
            break;
        }
        check();
    }
    printf("\n ******************************************************");
    printf("\n ITERATION    X1    FX1    X2    FX2     X3       FX3   ");
    printf("\n **********************************************************");

    if(flag==1)
    {
        while((fabs(x2 - x1))>=0.0001)
        {
            cnt++;
            fx1=fx2=fx3=0;

            fx1=func(x1);
            fx2=func(x2);

            x3=(x1+x2)/2;
            fx3=func(x3);

            printf("\n %d        %.3f  %.3f  %.3f  %.3f  %.3f  %.3f",cnt,x1,fx1,x2,fx2,x3,fx3);
            t=fx1*fx3;
            if(t>0)
            {
                x1=x3;
            }
            if(t<0)
            {
                x2=x3;
            }
        }
        printf("\n\t ROOT OF EQUATION IS %f:::",x3);
    }
    getch();
}


/***********************************OUTPUT***********************************/
PROGRAM FOR PARICULAR BISECTION GENERAL EQUATION ::::: LOG(X)-COS(X) INTIAL X1---->1 INTIAL X2---->2 ****************************************************** ITERATION X1 FX1 X2 FX2 X3 FX3 ****************************************************** 1 1.000 -0.540 2.000 0.717 1.500 0.105 2 1.000 -0.540 1.500 0.105 1.250 -0.218 3 1.250 -0.218 1.500 0.105 1.375 -0.056 4 1.375 -0.056 1.500 0.105 1.438 0.025 5 1.375 -0.056 1.438 0.025 1.406 -0.016 6 1.406 -0.016 1.438 0.025 1.422 0.004 7 1.406 -0.016 1.422 0.004 1.414 -0.006 8 1.414 -0.006 1.422 0.004 1.418 -0.001 9 1.418 -0.001 1.422 0.004 1.420 0.002 10 1.418 -0.001 1.420 0.002 1.419 0.001 11 1.418 -0.001 1.419 0.001 1.418 0.000 12 1.418 -0.001 1.418 0.000 1.418 -0.000 13 1.418 -0.000 1.418 0.000 1.418 -0.000 14 1.418 -0.000 1.418 0.000 1.418 -0.000 ******************************************************* ROOT OF EQUATION IS ::::: 1.41839
  
Share: 


Didn't find what you were looking for? Find more on BISECTION METHOD FOR PARTICULAR Or get search suggestion and latest updates.

Adelbert Fischer
Adelbert Fischer author of BISECTION METHOD FOR PARTICULAR is from Frankfurt, Germany.
 
View All Articles

Related Articles and Code:


 
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!