/******************************************************************************* * RESOLUTION OF A SET OF NON-LINEAR EQUATIONS * * ---------------------------------------------------------------------------- * * COPYRIGHT 1991, BY R.S. BAIN * * Originally wrapped by bain@luther.che.wisc.edu on Tue Mar 30 16:27:48 1993 * * * * As of this writing, we do not know how to contact Rod Bain, the * * author of NNES. * * * * F90 Release By David M. Gay (dmg@bell-labs.com) * * Bell Labs, Murray Hill * * 8 February 1999 * * ---------------------------------------------------------------------------- * * SAMPLE RUNS: * * Example #1 * * Solve non-linear system of size n=2: * * x1^2 + x1 + x2^2 - 2 = 0 * * x1^2 + x2 - x2^2 - 1 + log(x1) = 0 * * * * with initial guess; x1=1, x2=1 * * (The system is described in unit fcn.cpp). * * * * With default options (output=2), the output file EX1.OUT contains: * * * * * * *-----------------------------------------------------------------------* * * *-----------------------------------------------------------------------* * * * * * * * N N E S * * * * * * * * NONMONOTONIC NONLINEAR EQUATION SOLVER VERSION 1.05 * * * * * * * * COPYRIGHT 1991, BY R.S. BAIN * * * * * * * *-----------------------------------------------------------------------* * * *-----------------------------------------------------------------------* * * * * * * *-----------------------------------------------------------------------* * * *-----------------------------------------------------------------------* * * * * * * * INITIAL ESTIMATES INITIAL FUNCTION VALUES * * * * * * * * X( 1) = 1.000 F( 1) = 1.000 * * * * X( 2) = 1.000 F( 2) = 0.000 * * * * * * * * INITIAL OBJECTIVE FUNCTION VALUE = 0.500 * * * * * * * *-----------------------------------------------------------------------* * * *-----------------------------------------------------------------------* * * * * * * * CONVERGENCE REACHED; TERMINATION CODE: ............... 2 * * * * * * * * * * * * FINAL ESTIMATES FINAL FUNCTION VALUES * * * * * * * * X( 1) = 0.915553 F( 1) = 0.000005 * * * * X( 2) = 0.496200 F( 2) = -0.000004 * * * * * * * * FINAL OBJECTIVE FUNCTION VALUE: 2.057349e-011 * * * * * * * * * * * * TOTAL NUMBER OF ITERATIONS: .......................... 4 * * * * TOTAL NUMBER OF LINE SEARCH FUNCTION EVALUATIONS: .... 5 * * * * TOTAL NUMBER OF EXPLICIT JACOBIAN EVALUATIONS: ....... 16 * * * * TOTAL NUMBER OF FUNCTION EVALUATIONS: ................ 13 * * * * * * * *-----------------------------------------------------------------------* * * * * Example #2 * * Solve non-linear system of size n=4: * * 10.0*x + x2 + x3 + x4 - 20.0 + Sqr(sin(x1)) + Sqr(cos(x2)) = 0 * * x1 + 20.0*x2 + x3 + x4 - 48.0 + one/pow^6 = 0 * * Sqr(x1 + x2) + 30.0*x3 + x4 - 97.0 + log(x1) + log(x2+x3) = 0 * * x1 + x2 + x3 + 40.0*x4 - 166.0 + Sqr(x1) = 0 * * * * with initial guess; x1=1, x2=1, x3=1, x4=1 * * (The system is described in unit fcn.cpp). * * * * With default options (output=4), the output file EX2.OUT contains at the end:* * * * * -- / -- * * * * SUMMARY OF ITERATION RESULTS * * * * * * * * UPDATED ESTIMATES UPDATED FUNCTION VALUES * * * * * * * * X( 1) = 1.041 F( 1) = 0.000 * * * * X( 2) = 1.972 F( 2) = 0.000 * * * * X( 3) = 2.745 F( 3) = 0.000 * * * * X( 4) = 3.979 F( 4) = 0.000 * * * * * * * * OBJECTIVE FUNCTION VALUE: 3.071338e-011 * * * * * * * * STEP ACCEPTANCE CODE, ACPCOD: 12 * * * * * * * * CONVERGENCE TESTING * * * * * * * * MAXIMUM STEP SIZE: 0.001 STPTOL: 0.000 * * * * * * * * MAXIMUM ABSOLUTE FUNCTION: 0.000 FTOL: 0.000 * * * * * * * * * * * * CONVERGENCE REACHED; TERMINATION CODE: ............... 2 * * * * * * * * * * * * FINAL ESTIMATES FINAL FUNCTION VALUES * * * * * * * * X( 1) = 1.040648 F( 1) = 0.000004 * * * * X( 2) = 1.972398 F( 2) = 0.000006 * * * * X( 3) = 2.745049 F( 3) = 0.000003 * * * * X( 4) = 3.978974 F( 4) = 0.000000 * * * * * * * * FINAL OBJECTIVE FUNCTION VALUE: 3.071338e-011 * * * * * * * * * * * * TOTAL NUMBER OF ITERATIONS: .......................... 3 * * * * TOTAL NUMBER OF LINE SEARCH FUNCTION EVALUATIONS: .... 4 * * * * TOTAL NUMBER OF EXPLICIT JACOBIAN EVALUATIONS: ....... 12 * * * * TOTAL NUMBER OF FUNCTION EVALUATIONS: ................ 16 * * * * * * * *-----------------------------------------------------------------------* * * * * * * Visual C++ Release 1.1 By J-P Moreau, Paris * * (See help file nneshelp.txt). * * (www.jpmoreau.fr) * * * * Release 1.1: Added example #2 (03/30/2007). * ******************************************************************************** This program uses files utils.cpp, fcn.cpp, unnes.cpp, unnes1.cpp, unnes2.cpp, basis.cpp, basis_r.cpp. */ #include #include const mgll = 10, nunit=10; // not used here. REAL alpha, confac, delfac, delta, epsmch, etafac, fcn1new, fdtolj, ftol, lam0, mstpf, nsttol, omega, ratiof, sigma, stptol; int acptcr, example, i, itsclf, itsclx, jactyp, jupdm, maxexp, maxit, maxns, maxqns, minqns, n, narmij, niejev, njacch, njetot, output, qnupdm, stopcr, supprs, trmcod, trupdm; //pointers to matrices REAL **a, **h, **jac, **plee; // pointers to vectors REAL *boundl, *boundu, *delf, *fsave, *ftrack, *fvec, *fvecc, *hhpi, *rdiag, *s, *sbar, *scalef, *scalex, *sn, *ssdhat, *strack, *vhat, *xc, *xplus, *xsave; bool absnew, cauchy, deuflh, geoms, linesr, newton, overch; char help[10]; // not used here void *vmblock = NULL; FILE *fp; extern bool bypass; //cf. unnes.cpp void setup (bool *, bool *, bool *, bool *, bool *, bool *, bool *, int *, int *, int *, int *, int *, int *, int *, int *, int *, int *, int, int *, int *, int *, int *, int *, int *, int *, int *, REAL *, REAL *, REAL *, REAL *, REAL *, REAL *, REAL *, REAL *, REAL *, REAL *, REAL *, REAL *, REAL *, REAL *, REAL *, REAL *, REAL *, REAL *, REAL *, char *); void nnes (bool absnew, bool cauchy, bool deuflh, bool geoms, bool linesr, bool newton, bool overch, int acptcr, int *itsclf, int *itsclx, int jactyp, int jupdm, int *maxexp, int maxit, int maxns, int maxqns, int mgll, int minqns, int n, int narmij, int niejev, int njacch, int *njetot, int nunit, int *output, int qnupdm, int *stopcr, int supprs, int *trmcod, int trupdm, REAL *alpha, REAL *confac, REAL *delta, REAL *delfac, REAL epsmch, REAL *etafac, REAL *fcnnew, REAL *fdtolj, REAL *ftol, REAL *lam0, REAL *mstpf, REAL *nsttol, REAL *omega, REAL *ratiof, REAL *sigma, REAL *stptol, REAL **a, REAL * boundl, REAL *boundu, REAL *delf, REAL *fsave, REAL *ftrack, REAL *fvec, REAL *fvecc, REAL **h, REAL *hhpi, REAL **jac, REAL **plee, REAL *rdiag, REAL *s, REAL *sbar, REAL *scalef, REAL *scalex, REAL *sn, REAL *ssdhat, REAL *strack, REAL *vhat, REAL *xc, REAL *xplus, REAL *xsave, char *help); void main() { strcpy(help,"NONE"); example=2; // # example in fcn.cpp // open output text file if (example==1) fp = fopen("ex1.out","w"); else if (example==2) fp = fopen("ex2.out","w"); else fp = fopen("ex3.out","w"); if (example==1) n=2; else if (example==2) n=4; else n=6; // allocate memory for vectors and matrices vmblock = vminit(); boundl = (REAL *) vmalloc(vmblock, VEKTOR, n+1, 0); boundu = (REAL *) vmalloc(vmblock, VEKTOR, n+1, 0); delf = (REAL *) vmalloc(vmblock, VEKTOR, n+1, 0); fsave = (REAL *) vmalloc(vmblock, VEKTOR, n+1, 0); ftrack = (REAL *) vmalloc(vmblock, VEKTOR, n+1, 0); fvec = (REAL *) vmalloc(vmblock, VEKTOR, n+1, 0); fvecc = (REAL *) vmalloc(vmblock, VEKTOR, n+1, 0); hhpi = (REAL *) vmalloc(vmblock, VEKTOR, n+1, 0); rdiag = (REAL *) vmalloc(vmblock, VEKTOR, n+1, 0); s = (REAL *) vmalloc(vmblock, VEKTOR, n+1, 0); sbar = (REAL *) vmalloc(vmblock, VEKTOR, n+1, 0); scalef = (REAL *) vmalloc(vmblock, VEKTOR, n+1, 0); scalex = (REAL *) vmalloc(vmblock, VEKTOR, n+1, 0); sn = (REAL *) vmalloc(vmblock, VEKTOR, n+1, 0); ssdhat = (REAL *) vmalloc(vmblock, VEKTOR, n+1, 0); strack = (REAL *) vmalloc(vmblock, VEKTOR, n+1, 0); vhat = (REAL *) vmalloc(vmblock, VEKTOR, n+1, 0); xc = (REAL *) vmalloc(vmblock, VEKTOR, n+1, 0); xplus = (REAL *) vmalloc(vmblock, VEKTOR, n+1, 0); xsave = (REAL *) vmalloc(vmblock, VEKTOR, n+1, 0); a = (REAL **) vmalloc(vmblock, MATRIX, n+1, n+1); h = (REAL **) vmalloc(vmblock, MATRIX, n+1, n+1); jac = (REAL **) vmalloc(vmblock, MATRIX, n+1, n+1); plee = (REAL **) vmalloc(vmblock, MATRIX, n+1, n+1); if (! vmcomplete(vmblock)) { LogError ("No Memory", 0, __FILE__, __LINE__); return; } // initial guess for (i=0; i<=n; i++) { xc[i]=ONE; } setup(&absnew, &cauchy, &deuflh, &geoms, &linesr, &newton, &overch, &acptcr, &itsclf, &itsclx, &jactyp, &jupdm, &maxexp, &maxit, &maxns, &maxqns, &minqns, n, &narmij, &niejev, &njacch, &output, &qnupdm, &stopcr, &supprs, &trupdm, &alpha, &confac, &delta, &delfac, &epsmch, &etafac, &fdtolj, &ftol, &lam0, &mstpf, &nsttol, &omega, &ratiof, &sigma, &stptol, boundl, boundu, scalef, scalex, help); output = 4; // more conditions for example #3 if (example == 3) { boundl[3]=ZERO; boundl[4]=ZERO; boundl[6]=ZERO; nsttol=1e-16; stptol=1e-16; bypass=TRUE; } nnes(absnew, cauchy, deuflh, geoms, linesr, newton, overch, acptcr, &itsclf, &itsclx, jactyp, jupdm, &maxexp, maxit, maxns, maxqns, mgll, minqns, n, narmij, niejev, njacch, &njetot, nunit, &output, qnupdm, &stopcr, supprs, &trmcod, trupdm, &alpha, &confac, &delta, &delfac, epsmch, &etafac, &fcn1new, &fdtolj, &ftol, &lam0, &mstpf, &nsttol, &omega, &ratiof, &sigma, &stptol, a, boundl, boundu, delf, fsave, ftrack, fvec, fvecc, h, hhpi, jac, plee, rdiag, s, sbar, scalef, scalex, sn, ssdhat, strack, vhat, xc, xplus, xsave, help); if (example==1) printf("\n Results in file ex1.out.\n"); else if (example==2) printf("\n Results in file ex2.out.\n"); else printf("\n Results in file ex3.out.\n"); printf(" Program terminated...\n\n"); fclose(fp); // free memory vmfree(vmblock); } // end of file tnnes.cpp