Thursday, January 11, 2018

Fixed Point Iteration Method Program

#include 
#include 
#include 
#define E 0.0001
#define f(x) 3*x*x - 6*x + 2
#define g(x) (6*x-2)/(3*x)
int main(){
	float x0, x1, err;
	int count = 0;
	clrscr();
	printf("Enter Initial Guess : ");
	scanf("%f", &x0);
	printf("\nIteration\tInitialValue\tNewValue\n");
	do{
	x1 = g(x0);
	count++;
	printf("\n%d\t\t%0.4f\t\t%0.4f\n",count, x0,x1);
	err = (x1-x0)/x1;
	x0 = x1;
	}while(fabs(err) > E);
	printf("\nIteration : %d\n", count);
	printf("\nThe root is %0.4f", x1);
	getch();
	return 0;
}

No comments:

Post a Comment