Tuesday, February 14, 2017

How to Find Integer Solutions (if any) of a Nonlinear Systems of Equations


Jsun Yui Wong

The computer program listed below seeks to find integer solutions (if any) of the following nonlinear system, which is based on the nonlinear system of five variables on page 238 of Shoup [8].

         X(1) + X(2) + X(3) + X(4) = 31,
      
         X(1) * X(2) + X(2) * X(3) + X(4) * X(5) = 52,

         X(1) ^ 2 + X(3) * X(4) - X(2) ^ 2 + X(1) * X(5) = 86,

         X(1) - X(2) * X(4) + X(3) ^ 2 + X(5) ^ 3 = 19,

         X(1) * X(3) - X(2) ^ 3 * X(5) - X(5) * X(2) + X(3) ^ 2 * X(4) = 240.


0 DEFDBL A-Z

3 DEFINT J, K

4 DIM X(342), A(342), L(333), K(333)


12 FOR JJJJ = -32000 TO 32000


    14 RANDOMIZE JJJJ

    16 M = -1D+317

    91 FOR KK = 1 TO 5

        94 A(KK) = -10 + FIX(RND * 20)


    95 NEXT KK
    128 FOR I = 1 TO 3000000


        129 FOR K = 1 TO 5


            131 X(K) = A(K)
        132 NEXT K
        155 FOR IPP = 1 TO FIX(1 + RND * 3)

            181 B = 1 + FIX(RND * 5)


            182 IF RND < -.1 THEN 183 ELSE GOTO 189

            183 R = (1 - RND * 2) * A(B)
            186 X(B) = A(B) + (RND ^ 3) * R

            188 GOTO 191
            189 IF RND < .5 THEN X(B) = A(B) - FIX(1 + RND * 1.99) ELSE X(B) = A(B) + FIX(1 + RND * 1.99)


        191 NEXT IPP



        1001 X(4) = 31 - X(1) - X(2) - X(3)



        1004 REM

        1111 N96 = -52 + X(1) * X(2) + X(2) * X(3) + X(4) * X(5)


        1116 N97 = -86 + X(1) ^ 2 + X(3) * X(4) - X(2) ^ 2 + X(1) * X(5)
        1118 N98 = -19 + X(1) - X(2) * X(4) + X(3) ^ 2 + X(5) ^ 3
        1119 N99 = -240 + X(1) * X(3) - X(2) ^ 3 * X(5) - X(5) * X(2) + X(3) ^ 2 * X(4)
        1335 P = -ABS(N96) - ABS(N97) - ABS(N98) - ABS(N99)


        1499 IF P <= M THEN 1670
        1657 FOR KEW = 1 TO 5


            1658 A(KEW) = X(KEW)
        1659 NEXT KEW
        1661 M = P
        1666 NN96 = N96: NN97 = N97: NN98 = N98: NN99 = N99

    1670 NEXT I
    1888 IF M < -29 THEN 1999

    1917 PRINT A(1), A(2), A(3), A(4), A(5), M, JJJJ, NN96, NN97, NN98, NN99

1999 NEXT JJJJ


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

2      0      3        26       2
0      -32000      0      0      0
0

2      0      3        26       2
0      -31999      0      0      0
0

2      0      3        26       2
0      -31997      0      0      0
0

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 [9], the wall-clock time through
JJJJ=-31997 was 25 seconds, not including "Creating .EXE file..." time.

Acknowledgment

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

References
[1] R. Burden, J. Faires, A. Burden, Numerical Analysis, Tenth Edition. Cengage Learning, 2016.
[2] R. Burden, J. Faires, Numerical Analysis, Sixth Edition. Brooks/Cole Publishing Company, 1996.
[3] R. Burden, J. Faires, Numerical Analysis, Third Edition. PWS Publishers, 1985.
[4] D. Greenspan, V. Casulli, Numerical Analysis for Applied Mathematics, Science, and Engineering. Addison-Wesley Publishing Company, 1988
[5] L. W. Johnson, R. D. Riess, Numerical Analysis, Second Edition. Addison-Wesley Publishing Company, 1982
[6] 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.
[7] William H. Mills, A System of Quadratic Diophantine Equations, Pacific Journal of Mathematics, 3 (1953), pp. 209-220.
[9]  Terry E. Shoup, Applied Numerical Methods for the Microcomputer, Prentice-Hall, 1984.
[9] Wikipedia, QB64, https://en.wikipedia.org/wiki/QB64.

No comments:

Post a Comment