Friday, July 20, 2012

C Program for False Position Method 2





/*False Position Method*/

#include<stdio.h>

#include<conio.h>

#include<alloc.h>

#include<math.h>

#include<process.h>

#define f(x) log10(x*x*x)-0.7

double value(double);

void main()

{

double x,v,v1,v2,xr,xu,xl,xo=0,ea,et,tv;

double i,p,it=50;

clrscr();

puts("-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");

puts("Finding Root By Using False Position Method");

puts("-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");

puts("-------------------------------------------");

puts("Enter value of xl and xu ");

scanf("%lf %lf ",&xl,&xu);

puts("---------------------------------------------");

puts("Enter True Value and Iterations");

scanf("%lf %lf",&tv,&it);

puts("--------------------------------------------------");

i=0;

puts("Iteration\t Xr \t\t Ea\t\tEt");

while(1)

{

i++;

v1=f(xl);

v2=f(xu);

if(v1*v2>=0)

{

puts("Invalid Value of xl and xu");

getch();

exit(0);

}

xr=xu-(v2*(xl-xu)/(v1-v2));

ea=(xr-xo)*100/xr;

et=(tv-xr)*100/tv;

if(ea<0) /*--- Eliminating Error due to ---*/

ea=ea*-1; /*--- Negative sign of Ea ---*/

v=f(xr);

if(v==0||i==it)

{

printf("\n%3d\t\t%6.6lf\t\t%5.6lf\t\t%5.6lf",(int)i,xr,ea,et);

puts("\n-----------------------------------------------------------");

getch();

exit(0);

}

printf("\n%3d\t\t%6.6lf\t\t%5.6lf\t\t%5.6lf",(int)i,xr,ea,et);

if(v1*v<0)

xu=xr;

else

xl=xr;

xo=xr;

}

getch();

}

Output Of Program:-

-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-

Finding Root By Using False Position Method

-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-

---------------------------------------------------------------

Enter value of xl and xu

1

3

---------------------------------------------------------------

Enter True Value and Iterations

1.262803

10

---------------------------------------------------------------

Iteration Xr Ea Et

1 1.978088 100.000000 -56.642659

2 1.770376 11.732652 -40.194166

3 1.724625 2.652832 -36.571162

4 1.714334 0.600252 -35.756283

5 1.712009 0.135855 -35.572101

6 1.711482 0.030750 -35.530425

7 1.711363 0.006960 -35.520992

8 1.711336 0.001575 -35.518857

9 1.711330 0.000357 -35.518374

10 1.711329 0.000081 -35.518264

---------------------------------------------------------------


No comments:

Post a Comment