/*********************************************** * Roots of a polynomial by Bernouilli's method * * -------------------------------------------- * * Reference: "Methodes de calcul numerique By * * Claude Nowakowski, PSI Editions, * * France, 1981" [BIBLI 04]. * * * * C++ version by J-P Moreau * * (www.jpmoreau.fr) * * -------------------------------------------- * * SAMPLE RUN: * * * * Roots of a polynomial by Bernouilli's method * * * * Input order of polynomial: 4 * * * * Input coefficients of the polynomial: * * * * A( 0 ) = 1 * * A( 1 ) = 2 * * A( 2 ) = -13 * * A( 3 ) = -14 * * A( 4 ) = 24 * * * * ===== R O O T S ===== * * * * X1 = -4.0000 * * X2 = 3.0000 * * X3 = -2.0001 * * X4 = 1.0001 * * * ***********************************************/ #include #include #define SIZE 25 int k,nd; double temp,A[SIZE],Y[SIZE]; // Bernouilli's subroutine void Bernouilli() { // Labels: e5,e50,e100 int k,l,n,nroot; double er,s,x,x1; printf("\n ===== R O O T S =====\n\n"); n=nd; if (fabs(A[0])<1e-12) { printf(" Error: A(0) must be <> 0 !\n"); return; } for (k=0; k0; k--) Y[k]=Y[k-1]; } //l loop printf("\n Error: no convergence (error=%e)\n",er); return; e100: printf(" X%d = %9.4f\n",nroot,x); n--; if (n==0) return; A[1] += x; for (k=2; k