Sep 10, 2009

siedle method

#include
#include
#include

float ff (float x)
{
return (pow(x,2.0)-12.0);
}

void main()
{
int i=1;
float x1,x2,x3,e,f1,f2,f3;
clrscr();
printf("Enter value of tolerance : ");
scanf("%f",&e);
printf("enter x1 and x2 : ");
scanf("%f%f",&x1,&x2);
do{
printf("\n\n\n----------------------------------------------------");
printf("\n\n\nIteration %d",i);
printf("\n\n\nx1 = %f",x1);
printf("\t x2 = %f",x2);
f1=ff(x1);
f2=ff(x2);


x3=(x1*f2-x2*f1)/(f2-f1);
f3=ff(x3);
x1=x2;
x2=x3;
i++;
}while(fabs(f3)>e);
printf("\n\n\n------------------------------------------------\n\n");
printf("The root is : %f",x3);
getch();
}

No comments:

Post a Comment