Thursday, February 9, 2017

Solving a Nonlinear System of Equations


Jsun Yui Wong

The computer program listed below seeks to solve simultaneously the following nonlinear system of equations from page 665 of Burden, Faires, and Burden [1, p. 665, Exercise 6]:

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

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

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


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 = 96 TO 99

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


    95 NEXT KK
    128 FOR I = 1 TO 8000



        129 FOR K = 96 TO 99


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

            181 B = 96 + FIX(RND * 9)


            182 REM 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

        331 X(98) = X(96) * X(99) + X(97) - 4 * X(96)



        335 REM N98 = X(96) ^ 2 - 625 * X(97) ^ 2 - 1 / 4

        339 REM N99 = EXP(-X(96) * X(97)) + 20 * X(98) + (10 * 3.141592654 - 3) / 3

        351 N97 = -X(97) * X(99) - X(96) + 3 * X(97) - 2 * X(98)

        353 N98 = -X(98) * X(99) + X(96) - 2 * X(97) + 3 * X(98)

        355 REM N98 = -X(98) * X(99) + X(97) - 4 * X(96)
        359 N99 = -1 + X(96) ^ 2 + X(97) ^ 2 + X(98) ^ 2

        1335 P = -ABS(N98) - ABS(N99) - ABS(N97)


        1499 IF P <= M THEN 1670
        1657 FOR KEW = 96 TO 99


            1658 A(KEW) = X(KEW)
        1659 NEXT KEW
        1661 M = P

    1670 NEXT I
    1888 IF M < -.0000001 THEN 1999

    1917 PRINT A(96), A(97), A(98), A(99), M, JJJJ

1999 NEXT JJJJ

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

-2.493654401671402D-15      .7071068014058323      .7071068014058398
 .9999999980999506            -5.98758606780458D-08      -31892

8.33475294629724D-18        .7071067794128311      .7071067794128311
1.000000018454071            -3.111482494474582D-08      -31647

7.720047542022925D-10        .707106789031514       .7071067867154998
1.000000005454302             -2.663362473018802D-08      -31561

3.038262892746562D-09        .7071067999755675      .707106790860779
1.00000002148609               -7063893669385927D-08      -30989

4.231662939811113D-10      .7071067906077655      .7071067893382665
.9999999970098467            -2.908354898334712D-08      -30691

0                     -.7071067723044366           -.7071067723044366
1.00000000499632             -3.218826598465926D-08      -30366

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 [8], the wall-clock time through
JJJJ=-30366 was 30 seconds.

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.
[8] Wikipedia, QB64, https://en.wikipedia.org/wiki/QB64.

No comments:

Post a Comment