Thursday, January 11, 2018

Newton Raphson Method Program

#include
#include
#include
#define E 0.0001
#define f(x) x*x+4*x-9
#define fd(x) 2*x+4
int main(){
    int count=1;
    float x0, xn, fx, fdx, fxn, err;
    clrscr();
    printf("Enter initial guess: ");
    scanf("%f", &x0);
    printf("\nValue\tFunctional Value\tDerivative Value\n");
    do{
	count++;
	fx=f(x0);
	fdx=fd(x0);
	printf("%0.4f\t\t%0.4f\t\t%0.4f\n", x0,fx, fdx);
	err=fabs((xn-x0)/xn);
	x0=xn;
    }while(err>E);
    printf("\nFunctional Value: %0.4f", fxn);
    printf("\nNo of Iteration: %d", count);
    getch();
    return 0;
}

No comments:

Post a Comment