Attribute VB_Name = "Module6" '******************************************************************************** '* 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 RUN: * '* 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 module fcn.bas). * '* * '* 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 F( 1) = 1 * * '* * X( 2) = 1 F( 2) = 0 * * '* * * * '* * INITIAL OBJECTIVE FUNCTION VALUE = .5 * * '* * * * '* *-----------------------------------------------------------------------* * '* *-----------------------------------------------------------------------* * '* * * * '* * CONVERGENCE REACHED; TERMINATION CODE: ............... 2 * * '* * * * '* * * * '* * FINAL ESTIMATES FINAL FUNCTION VALUES * * '* * * * '* * X( 1) = .915552905659849 F( 1) = 4.62630579576954E-06 * * '* * X( 2) = .496200158790538 F( 2) = -4.44345361584316E-06 * * '* * * * '* * FINAL OBJECTIVE FUNCTION VALUE: 2.05734926760602E-11 * * '* * * * '* * * * '* * TOTAL NUMBER OF ITERATIONS: .......................... 4 * * '* * TOTAL NUMBER OF LINE SEARCH FUNCTION EVALUATIONS: .... 5 * * '* * TOTAL NUMBER OF EXPLICIT JACOBIAN EVALUATIONS: ....... 4 * * '* * TOTAL NUMBER OF FUNCTION EVALUATIONS: ................ 13 * * '* * * * '* *-----------------------------------------------------------------------* * '* * '* Example #2 * '* Solve non-linear system of size n=4: * '* 10 * x1 + x2 + x3 + x4 - 20 + Sin(x1) ^ 2 + Cos(x2) ^ 2 = 0 * '* x1 + 20 * x2 + x3 + x4 - 48 + one / x1 ^ 6 = 0 * '* (x1 + x2) ^ 2 + 30 * x3 + x4 - 97 + Log(x1) + Log(x2 + xc3) = 0 * '* x1 + x2 + x3 + 40 * x4 - 166 + x1 ^ 2 = 0 * '* * '* with initial guess; x1=1, x2=1, x3=1, x4=1 * '* (The system is described in module fcn.bas). * '* * '* With default options (output=4), the output file EX1.OUT contains at the end:* '* * '* * -- / -- * * '* * SUMMARY OF ITERATION RESULTS * * '* * * * '* * UPDATED ESTIMATES UPDATED FUNCTION VALUES * * '* * * * '* * X( 1) = 1.04064753487537 F( 1) = -1.71722511682626E-07 * * '* * X( 2) = 1.97239791509122 F( 2) = -2.65980973206603E-06 * * '* * X( 3) = 2.74504904012639 F( 3) = -1.0555637144638E-06 * * '* * X( 4) = 3.97897395405217 F( 4) = -5.59778929876131E-08 * * '* * * * '* * OBJECTIVE FUNCTION VALUE: 4.11071235580385E-12 * * '* * * * '* * STEP ACCEPTANCE CODE, ACPCOD: 12 * * '* * * * '* * CONVERGENCE TESTING * * '* * * * '* * MAXIMUM STEP SIZE: 1.51602760707335E-06 * * '* * (STPTOL: 3.75603119159285E-11) * * '* * * * '* * MAXIMUM ABSOLUTE FUNCTION: 2.65980973206603E-06 * * '* * (FTOL: 6.12864682584406E-06) * * '* * * * '* * * * '* * CONVERGENCE REACHED; TERMINATION CODE: ............... 2 * * '* * * * '* * * * '* * FINAL ESTIMATES FINAL FUNCTION VALUES * * '* * * * '* * X( 1) = 1.04064753487537 F( 1) = -1.71722511682626E-07 * * '* * X( 2) = 1.97239791509122 F( 2) = -2.65980973206603E-06 * * '* * X( 3) = 2.74504904012639 F( 3) = -1.0555637144638E-06 * * '* * X( 4) = 3.97897395405217 F( 4) = -5.59778929876131E-08 * * '* * * * '* * FINAL OBJECTIVE FUNCTION VALUE: 4.11071235580385E-12 * * '* * * * '* * * * '* * TOTAL NUMBER OF ITERATIONS: .......................... 7 * * '* * TOTAL NUMBER OF LINE SEARCH FUNCTION EVALUATIONS: .... 8 * * '* * TOTAL NUMBER OF EXPLICIT JACOBIAN EVALUATIONS: ....... 7 * * '* * TOTAL NUMBER OF FUNCTION EVALUATIONS: ................ 36 * * '* * * * '* * NUMBER OF STEPS ACCEPTED BY FUNCTION VALUE ONLY: ..... 0 * * '* * NUMBER OF STEPS ACCEPTED BY STEP SIZE VALUE ONLY: .... 0 * * '* * NUMBER OF STEPS ACCEPTED BY EITHER CRITERION: ........ 7 * * '* * * * '* *-----------------------------------------------------------------------* * '* * '* Visual Basic 4.0 Release 1.1 By J-P Moreau, Paris * '* (See help file nneshelp.txt). * '* (www.jpmoreau.fr) * '* * '* Release 1.1 (03/29/2007): Added example of size 4. * '******************************************************************************** 'This program uses files utils.bas, fcn.bas, nnes.bas, nnes1.bas, nnes2.bas DefDbl A-H, O-Z DefInt I-N Const mgll = 10, nunit = 10 'not used here Dim mstpf As Double Dim nsttol As Double Dim acptcr As Integer Dim example As Integer Dim qnupdm As Integer Dim stopcr As Integer Dim supprs As Integer Dim trupdm As Integer 'matrices defined as vectors ( example: element a(i,j) is a((i-1)*ISIZE+j) ) Dim a(ISIZE * ISIZE) Dim h(ISIZE * ISIZE) Dim jac(ISIZE * ISIZE) As Double Dim plee(ISIZE * ISIZE) Dim boundl(ISIZE), boundu(ISIZE), delf(ISIZE), fsave(ISIZE), ftrack(ISIZE) Dim fvec(ISIZE), fvecc(ISIZE), hhpi(ISIZE), rdiag(ISIZE), s(ISIZE), sbar(ISIZE) Dim scalef(ISIZE), scalex(ISIZE), sn(ISIZE), ssdhat(ISIZE), strack(ISIZE) Dim vhat(ISIZE), xc(ISIZE), xplus(ISIZE), xsave(ISIZE) 'booleans defined as integers (0 or 1) Dim absnew As Integer Dim cauchy As Integer Dim deuflh As Integer Dim geoms As Integer Dim overch As Integer Sub Exec_nnes() 'main subroutine of project PNNES example = 3 '# example in FCN.BAS 'open output text file If example = 1 Then Open "EX1.OUT" For Output As #1 ElseIf example = 2 Then Open "EX2.OUT" For Output As #1 Else Open "EX3.OUT" For Output As #1 End If If example = 1 Then n = 2 ElseIf example = 2 Then n = 4 Else n = 6 End If 'initial guess For i = 1 To n xc(i) = one Next i 'initialize parameters and options 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 = 5 'more conditions for example #3 If example = 3 Then boundl(3) = zero boundl(4) = zero boundl(6) = zero nsttol = 1E-16 stptol = 1E-16 bypass = 1 End If 'call main subroutine of module #5 nnes absnew, cauchy, deuflh, geoms, linesr, newton, overch, acptcr, _ itsclf, itsclx, jupdm, maxns, maxqns, minqns, n, narmij, niejev, _ njacch, qnupdm, stopcr, supprs, trupdm, alpha, confac, delta, delfac, _ etafac, fcn1new, fdtolj, ftol, 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 Form1.Print If example = 1 Then Form1.Print " Results in file ex1.out." ElseIf example = 2 Then Form1.Print " Results in file ex2.out." Else Form1.Print " Results in file ex3.out." End If Form1.Print " Program terminated..." Close #1 End Sub