Attribute VB_Name = "Module3" '******************************************************** '* Examples of non-linear system for UNNES * '* * '* Release 1.1 (03/29/2007): Added Example of size n=4 * '******************************************************** DefDbl A-H, O-Z DefInt I-N Sub fcn1(overfl As Integer, n, fvec(), xc()) overfl = False nfetot = nfetot + 1 ' Nonlinear systems to solve ' Example #1: ' x1^2 + x1 + x2^2 - 2 = 0 ' x1^2 + x2 - x2^2 - 1 + log(x1) = 0 ' Example #2: ' 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 ' Example #3 (stiff system): ' Hiebert 's 2nd Chemical Engineering Problem ' source: Hiebert; Sandia Technical Report #SAND80-0181 ' Sandia National Laboratories, Albuquerque, NM (1980) ' X1 X2 + X4 - 0.001 = 0 ' X5 X6 - 55 = 0 ' X1 + X2 + X3 + 2X5 + X6 - 110.001 = 0 ' X1 - 0.1X2 = 0 ' X1 - 10000 X3 X4 = 0 ' X5 - 5.5e15 X3 X6 = 0 ' solution: (8.264e-5, 8.264e-4, 9.091e-5, 9.091e-5, 55, 1.1e-10) If n = 2 Then fvec(1) = xc(1) * xc(1) + xc(1) + xc(2) * xc(2) - 2# fvec(2) = xc(1) * xc(1) + xc(2) - xc(2) * xc(2) - 1# + Log(xc(1)) End If If n = 4 Then fvec(1) = 10# * xc(1) + xc(2) + xc(3) + xc(4) - 20# + Sin(xc(1)) ^ 2 + Cos(xc(2)) ^ 2 fvec(2) = xc(1) + 20# * xc(2) + xc(3) + xc(4) - 48# + one / xc(1) ^ 6 fvec(3) = (xc(1) + xc(2)) ^ 2 + 30# * xc(3) + xc(4) - 97# + Log(xc(1)) + Log(xc(2) + xc(3)) fvec(4) = xc(1) + xc(2) + xc(3) + 40# * xc(4) - 166# + xc(1) ^ 2 End If If n = 6 Then fvec(1) = xc(1) + xc(2) + xc(4) - 0.001 fvec(2) = xc(5) + xc(6) - 55# fvec(3) = xc(1) + xc(2) + xc(3) + 2# * xc(5) + xc(6) - 110.001 fvec(4) = xc(1) - 0.1 * xc(2) fvec(5) = xc(1) - 10000# * xc(3) * xc(4) fvec(6) = xc(5) - 5.5E+15 * xc(3) * xc(6) End If End Sub Sub jacob(overfl As Integer, n, jac() As Double, xc()) 'Dummy subroutine to calculate jacobian analytically overfl = 0 For i = 1 To n For j = 1 To n jac((i - 1) * ISIZE + j) = zero Next j Next i End Sub