/**************************************************** * ROOT TESTING PROGRAM OF A POLYNOMIAL * * ------------------------------------------------- * * Ref.: Basic Scientific Subroutines Vol. II * * By F.R. Ruckdeschel. BYTE/McGRAW-HILL, 1981 * * [BIBLI 01]. * * ------------------------------------------------- * * C++ version by J-P Moreau * * (www.jpmoreau.fr) * * ------------------------------------------------- * * SAMPLE RUN: * * (Example: Where to look for roots of polynomial * * X^5+5*X^4+10*X^3+10*X^2+5*X+1) * * * * This program will help you determine * * where to look for roots of a polynomial. * * * * What is the degree of the polynomial: 5 * * * * Input the polynomial coefficients as prompted: * * * * A( 0) = 1 * * A( 1) = 5 * * A( 2) = 10 * * A( 3) = 10 * * A( 4) = 5 * * A( 5) = 1 * * * * There are 5 roots. * * * * The magnitude of the largest root is <= 2.236068 * * * * There is at least one negative real root. * * * * There are at most 5 negative real roots. * * * ****************************************************/ #include #include // LABELS: e100,e200,e300 double aa, A[10]; int b,c,d,i,n; void main() { printf(" This program will help you determine \n"); printf(" where to look for roots of a polynomial.\n\n"); printf(" What is the degree of the polynomial: "); scanf("%d",&n); printf("\n Input the polynomial coefficients as prompted:\n\n"); for (i=0; i0) goto e100; printf(" There are at least two complex roots.\n\n"); return; e100: aa=sqrt(aa); printf("\n The magnitude of the largest root is <= %f\n\n",aa); aa=-1.0; if ((n % 2)==0) aa=-aa; aa=A[0]/aa; // b will flag a negative root b=0; if (aa>0) goto e200; printf(" There is at least one negative real root.\n\n"); b=1; e200: // Test for Descartes rule nø 1 c=0; for (i=1; i1) printf(" There are at most %d positive ",c); if (c==1) printf("real root.\n\n"); if (c>1) printf("real roots.\n\n"); // Test for Descartes rule nø 2 d=0; for (i=1; i0) d++; if (d==1) printf(" There is at most one negative "); if (d>1) printf(" There are at most %d negative ",d); if (d==1) printf("real root.\n\n"); if (d>1) printf("real roots.\n\n"); if ((c % 2)==0) goto e300; printf(" There is at least one positive real root.\n"); e300: if ((d % 2)==0) return; if (b==0) printf(" There is at least one negative real root.\n"); printf("\n\n"); } // End of file Roottest.cpp