Logo 
Search:

C Programming Articles

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

Generalized Newton Rapson for One variable

Posted By: Adalwin Fischer     Category: C Programming     Views: 2397

Generalized Newton Rapson for One variable.

Code for Generalized Newton Rapson for One variable in C Programming

#include<stdio.h>
#include<conio.h>
#include<math.h>
#define E 0.0001
float f(float t)
{
    return((exp(-t))-t);
}
float df(float t)
{
    return (-(exp(-t))-1);
}
void main()
{
    int ctr,ctr1,po,ctr3;
    float FX1=0.0,F_X=0.0;
    float R1,X0,temp;


    clrscr();


    printf("\nEnter the Root::");
    flushall();
    scanf("%f",&R1);

    X0=R1;

//Puting the value in f(x)

    FX1  = f(R1);

//Putting the value in f!(x)

    F_X  = df(R1);

    printf("\n==========================================================");
    printf("\nNO\tX0\tFX1\tF_X");
    printf("\n==========================================================");

    ctr3=0;
    do
    {
        F_X=FX1=0;

        F_X = df(X0);

        FX1 = f(X0);

        temp=X0;

        X0 = X0 - (FX1/F_X);

        printf("\n%d\t%.4f\t%.4f\t%.4f\n",ctr3+1,X0,FX1,F_X);
        ctr3++;

    }
    while((fabs(temp-X0))>=E);
    printf("\n%.4f",X0);


    getch();
}


/***********************************OUTPUT*********************************

Enter the Root::0.5

==========================================================
NO X0 FX1 F_X
==========================================================
1 0.5663 0.1065 -1.6065

2 0.5671 0.0013 -1.5676

3 0.5671 0.0000 -1.5671

0.5671

/******************************************************************************/
  
Share: 

 
 

Didn't find what you were looking for? Find more on Generalized Newton Rapson for One variable Or get search suggestion and latest updates.

Adalwin Fischer
Adalwin Fischer author of Generalized Newton Rapson for One variable 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!