/**************************************************** * Program to demonstrate NextRoot subroutine * * ------------------------------------------------- * * Reference: BASIC Scientific Subroutines, Vol. II * * By F.R. Ruckdeschel, BYTE/McGRAWW-HILL, 1981 [1]. * * * * C++ version by J-P Moreau, Paris. * * (www.jpmoreau.fr) * * ------------------------------------------------- * * SAMPLE RUN: * * (Example: Find another root of sin(x/2)) * * * * How many rootd have been determined: 3 * * * * Input the roots as prompted: * * * * A( 1) = 0 * * A( 2) = 119.38052 * * A( 3) = 75.398223 * * * * Input the initial guess: * * * * X0 = 75 * * * * Convergence criterion: .001 * * * * Maximum number of iterations: 20 * * * * * * The calculated zero is X = 50.265482 * * * * The associated Y value is Y = 0.000000 * * * * The number of steps was: 4 * * * ****************************************************/ #include #include double A[10]; int i,l,m,n; double e,x0,x1,z,z1; //******************************************* // Function subroutine with 1st derivative void Y(double x,double *yy,double *y1) { *yy=sin(x/2); // derivative *y1 = 0.5*cos(x/2); } //******************************************* /*********************************************** * NextRoot subroutine * * -------------------------------------------- * * This routine determines additional roots of * * a function Y(x), given a set of already * * established roots. Method applied is Newton- * * Raphson iteration. The l established roots * * are in A(i). The routine requires an initial * * guess, x0, and an accuracy criteria, e. It * * also requires a maximum number of iterations.* ***********************************************/ void Next_Root() { //Label: e100 double b,yy,y1; int i; n=0; // Given x0, find Y/Y" e100: Y(x0,&yy,&y1); b=y1/yy; for (i=1; i=m) return; if (fabs(x1-x0)