/*Program 2.3 : ScanRoot.c Purpose: Search for intervals that containing one or an odd number of roots, or poles, or both. Author : Wachara Rodsumrid. Last update : 07 MAR 94 **************************************************************/ #include
#include
#include
double tf(double); /* Target Function */ void main() { double a, /* starting value of x */ b, /* ending value of x */ h, /* constant increment of interval */ x, /* any value of x */ y, /* functional value at x */ yb; char buffer[255]; int i,found; clrscr(); printf("\n\t\tSearch for Interval that containing roots."); printf("\n\t\t=========================================="); printf("\nStarting value of x : ");gets(buffer); a =atof(buffer); printf("Ending value of x : ");gets(buffer); b = atof(buffer); printf("Increment of x : ");gets(buffer); h = atof(buffer); if ( a > b) { x = b; b= a; a= x; } i = 0; x = a; found=0; while ( x < b) { y = tf(x); yb = tf(x+h); i+=1; if ( y*yb < 0 ) { printf("\nInterval that contain root(s) : [%g, %g]",x,x+h); found +=1; } x += h; } printf("\n\n Found %d interval !!\n",found); exit(0); } double tf(double h) { return(3.284*exp(-(h-36089)/20806) - 7.35); }