Sunday, October 18, 2015

Finding Multiple Solutions of a Nonlinear System of Four Equations from the Literature, QB64 Edition

Jsun Yui Wong

"We make an extreme, but wholly defensible, statement: There are no good, general methods for solving systems of more than one nonlinear equation. Furthermore, it is not hard to see why (very likely) there never will be any good, general methods": Press, Teukolsky, Vetterling, and Flannery [3, 2007, p. 473].

Based on the computer program in Wong [6], , the following computer program tries to find multiple solutions of the following nonlinear system of equations from Burden and Faires [1, p. 559].

X(1)*X(2)*X(3)*X(4)-1=0
2*X(1)+X(2)+X(3)+X(4)-5=0
X(1)+2*X(2)+X(3)+X(4)-5=0
X(1)+X(2)+2*X(3)+X(4)-5=0

The following computer program uses qb64v1000-win [4, 5].

0 DEFDBL A-Z
3 DEFINT I, J, K
4 DIM X(42), A(42), L(33), K(33)
5 FOR JJJJ = -32000 TO 32000
    14 RANDOMIZE JJJJ
    16 M = -1D+17
    91 FOR KK = 1 TO 4
        94 A(KK) = -10 + RND * 20


    95 NEXT KK


    128 FOR I = 1 TO 20000


        129 FOR K = 1 TO 4
            131 X(K) = A(K)
        132 NEXT K

        155 FOR IPP = 1 TO FIX(1 + RND * 3)


            181 B = 1 + FIX(RND * 4)

            183 R = (1 - RND * 2) * A(B)


            187 IF RND < .333 THEN X(B) = A(B) + RND * R ELSE IF RND < .5 THEN X(B) = A(B) + RND ^ 4 * R ELSE X(B) = A(B) + RND ^ 7 * R


        211 NEXT IPP


        1141 X(1) = -2## * X(2) - X(3) - X(4) + 5##

        1142 N1 = 2## * X(1) + X(2) + X(3) + X(4) - 5##


        1145 N2 = X(1) + X(2) + 2## * X(3) + X(4) - 5##


        1150 N3 = X(1) * X(2) * X(3) * X(4) - 1##

        1230 P = -ABS(N1) - ABS(N2) - ABS(N3)


        1451 IF P <= M THEN 1670
        1657 FOR KEW = 1 TO 4
            1658 A(KEW) = X(KEW)
        1659 NEXT KEW
        1661 M = P
    1670 NEXT I
    1890 IF M < -.00001 THEN 1999


    1912 PRINT A(1), A(2), A(3), A(4), M, JJJJ

1999 NEXT JJJJ

This computer program was run with qb64v1000-win [4, 5]. Copied by hand from the screen, the computer program’s complete output through
JJJJ=  -17140 is shown below:

.868865346823489            .8688653468237607                .8688653469202664
1.524538612608723         -9.537550665978365D-06         -25909

.8688854102009361          .868885410311283                  .8688854107102401
1.524458358466258         -7.09426504664568D-06          -20487

1.000001450489441          1.000001449252298                 1.000001450135191
.9999942008707722         -1.451391252784752D-06         -17140

Above there is no rounding by hand; it is just straight copying by hand from the screen.

On a personal computer with a Pentium Dual-Core CPU E5200 @2.50GHz, 2.50 GHz, 960 MB of RAM and with qb64v1000-win [4, 5], the wall-clock time for obtaining the output through JJJJ= -17140 was eleven minutes.

Acknowledgment

I would like to acknowledge the encouragement of Roberta Clark and Tom Clark.

References

[1] R. Burden, J. D. Faires. Numerical Analysis, Fifth Ed. PWS-Kent Publishing Company, 1993.

[2] Microsoft Corp. BASIC, second edition (May 1982), Version 1.10. Boca Raton, Florida: IBM Corp., Personal Computer, P. O. Box 1328-C, Boca Raton, Florida 33432, 1981.

[3] W. H. Press, S. A. Teukolsky, W. T. Vetterling, B. P. Flannery. Numerical Recipes: the Art of Scientific Computing, Third Ed. Cambridge University Press, 2007.

[4] E.K. Virtanen (2008-05-26). “Interview With Galleon”.
http://www.basicprogramming.org/PCOPY! issue70/#galleoninterview

[5] Wikipedia, QB64, https://en.wikipedia.org/wiki/QB64

[6] Jsun Yui Wong (April 6, 2010).  Finding Multiple Solutions of a Nonlinear System of Four Equations from the Literature.
http://wongsnewnewblog.blogspot.ca/2010/04/finding-multiple-solutions-of-nonlinear.html

No comments:

Post a Comment