/* * FIXED-POINT ALGORITHM 2.2 * * To find a solution to p = g(p) given an * initial approximation p0 * This code is to solve Illustration problem on Page 61 of the textbook. * Formulation (d) is used. * * INPUT: initial approximation; tolerance TOL; * maximum number of iterations NO. * * OUTPUT: approximate solution p or * a message that the method fails. */ #include #include #include #include #define true 1 #define false 0 static double G(double ); /* function g */ using namespace std; int main() { double TOL, P0, P; int I, NO, FLAG = 2, OK; char AA; FILE *OUP[1]; // P0 = 1.5; // init. guess P0 = 2.5; // init. guess TOL = 1.0e-7; // tolerance for |p-p0| NO = 200; // max. number of iterations /* STEP 1 */ I = 1; /* STEP 2 */ OK = true; while(I<=NO && OK) { /* STEP 3 */ /* compute P(I) */ P = G(P0); if (FLAG == 2) cout<