Logo 
Search:

C Programming Articles

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

Secant for particular equation

Posted By: Guilherme Silva     Category: C Programming     Views: 2421

Program for Secant for particular equation.

Code for Secant for particular equation in C Programming

#include<stdio.h>
#include<conio.h>
#include<math.h>
#define E 0.001

float f (float x)
{
    return (cos(x)-(x*exp(x)));
}
void main()
{
    int ctr,temp,ctr1;
    float res,res1;
    int p,NO;
    float X1=0.00,X2=0.00;
    float X3,FX1,FX2,FX3;
    int co[10];
    clrscr();

//For Scanning X1 and X2

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

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

    ctr1=0;
    clrscr();

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

    do
    {

        FX1=FX2=FX3=0;
        FX1  = f(X1);
        FX2  = f(X2);


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

        FX3  = f(X3);

        printf("\n%d\t%.4f\t%.4f\t%.4f\t%.4f\t%.4f\t%.4f",ctr1+1,X1,FX1,X2,FX2,X3,FX3);

        X1=X2;
        FX1=FX2;
        X2=X3;
        FX2=FX3;
        ctr1++;
    }while(fabs(FX3)>=E );

    printf("\n\n%.4f",X3);

    getch();
}
  
Share: 


Didn't find what you were looking for? Find more on Secant for particular equation Or get search suggestion and latest updates.

Guilherme  Silva
Guilherme Silva author of Secant for particular equation is from Salvador, Brazil.
 
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!