Newsgroups: comp.lang.apl
Path: watmath!watserv2.uwaterloo.ca!torn!cs.utexas.edu!swrinde!emory!sol.ctr.columbia.edu!The-Star.honeywell.com!umn.edu!csus.edu!sfsuvax1.sfsu.edu!emclean
From: emclean@sfsuvax1.sfsu.edu (Emmett McLean)
Subject: Re: Matrix Inverse in APL2
Message-ID: <1993Jan16.105448.26408@csus.edu>
Sender: news@csus.edu
Organization: San Francisco State University
References: <726871483snz@apl.demon.co.uk> <1476@kepler1.rentec.com> <1993Jan15.183816.29350@csi.jpl.nasa.gov>
Date: Sat, 16 Jan 1993 10:54:48 GMT
Lines: 96

   NB. 
   NB.    The verb my_inv finds the inverse Hilbert matrix using
   NB.    Hilberts' "magic" formula. The row norms after
   NB.    matrix multiplication and subtracting the identity 
   NB.    matrix are shown for four cases : 

   NB.    1. jsinv (+/ .*) hilbert
   NB.    2. myinv (+/ .*) hilbert
   NB.    3. hilbert (+/ .*) jsinv
   NB.    4. hilbert (+/ .*) myinv

   NB.    Can anyone explain the variations of results ?
   NB.    BTW  Sam, 
   hilbert=. %@(_1&+@([ +/ [))@(1&+@(i.@[))    NB. ???????

   NB.   isn't :
   hilbert =. %@>:@+/~i. 
   hilbert =. (%\ (i.&.<:)@+:)
   NB. easier ?


   NB.    Emmett
   
   g1 =.(# ,:@(i.@-)) ! (#"1 ,.@(+ i.))
   g2 =.((, ]) $ (# |.@i.)) ! ((, ]) $ (+ i.))
   g3 =.*:@(((, ]) $ (# i.)) ! (+/~@i.))
   g4 =.>:@(+/~)@i.
   g5 =._1&^@(+/~@i.)
   js_inv =.%.@%@>:@(+/~)@i.
   my_inv =. g1@] * g2@] * g3@] * g4@] * g5@]
   dif1 =. '(=/~i.y.) - (js_inv (+/ .*) hilbert) y.':11
   dif2 =. '(=/~i.y.) - (my_inv (+/ .*) hilbert) y.':11
   dif3 =. '(=/~i.y.) - (hilbert (+/ .*) js_inv) y.':11
   dif4 =. '(=/~i.y.) - (hilbert (+/ .*) my_inv) y.':11
   row_norm1 =. '; >./ (+/)"1 dif1 y.':11 
   row_norm2 =. '; >./ (+/)"1 dif2 y.':11 
   row_norm3 =. '; >./ (+/)"1 dif3 y.':11 
   row_norm4 =. '; >./ (+/)"1 dif4 y.':11 
   test =. (,. ; (row_norm1"0),(row_norm2"0),(row_norm3"0),(row_norm4"0))@i.
   hilbert =. %@g4
   hilbert 3
       1      0.5 0.333333
     0.5 0.333333     0.25
0.333333     0.25      0.2
   my_inv 3
  9  _36   30
_36  192 _180
 30 _180  180
   
   NB.    test 20  NB. Jv6.2 on the NeXT
   NB. +--+----------------------------------------------------+
   NB. | 0|          __           __           __            __|
   NB. | 1|           0            0            0             0|
   NB. | 2|1.110223e_16 2.220446e_16 _1.48102e_16  1.110223e_16|
   NB. | 3|4.819662e_12 1.554312e_15 4.684838e_14  5.551115e_16|
   NB. | 4| 9.319971e_9 6.683543e_14 1.112868e_12  3.219647e_15|
   NB. | 5| 9.522846e_6 1.625367e_12 2.204261e_10  1.604272e_14|
   NB. | 6|    0.002266  1.19087e_11   4.9098e_11  8.160139e_14|
   NB. | 7|    0.532052  1.276476e_9  1.455863e_8  1.411538e_12|
   NB. | 8| 1271.449753  1.163426e_8  1.474694e_5  5.950751e_11|
   NB. | 9|  1.458664e7  6.310875e_7     0.009784  5.144933e_10|
   NB. |10|  9.380324e8  6.332994e_7     0.024738   4.307937e_8|
   NB. |11|  4.762183e8     0.000426     0.003141   1.499891e_6|
   NB. |12| 2.462249e11     0.005837     0.010152   1.971535e_5|
   NB. |13| 2.763563e11     4.605057     0.017472      0.444814|
   NB. |14|  5.80318e13   243.060791     0.038833      4.576476|
   NB. |15| 3.207627e16 14290.554688     0.217395   2836.057481|
   NB. |16| 1.247085e17     361334.5     0.894601   2976.238146|
   NB. |17| 1.510237e13    1.05589e7     0.111945 991632.890941|
   NB. |18| 3.691914e15   2.337603e8     0.234019   _9.394945e6|
   NB. |19| 4.359375e13   2.078688e9      0.14803   _3.540873e8|
   NB. +--+----------------------------------------------------+
   NB.    
    test 20  NB. Jv6.2 on the NeXT
NB. +--+-----------------------------------------------+
NB. | 0|_1.70141e38 _1.70141e38 _1.70141e38 _1.70141e38|
NB. | 1|          0           0           0           0|
NB. | 2|2.05391e_15           0 1.11022e_16           0|
NB. | 3|2.31903e_12           0 1.04361e_14           0|
NB. | 4|2.54822e_10           0  1.4877e_13           0|
NB. | 5|  2.0009e_6           0 2.30962e_11           0|
NB. | 6|0.000478849 9.09495e_13 1.79767e_11           0|
NB. | 7|   0.954606 5.82077e_11  5.27031e_8 5.68434e_14|
NB. | 8|    1080.36  6.51926e_9  1.27791e_6  7.27283e_9|
NB. | 9|  3.04825e6  1.19209e_7  0.00129511   1.1001e_7|
NB. |10|  1.19212e9  2.86102e_6   0.0142876  1.14821e_6|
NB. |11|  1.89404e8 0.000259399  0.00710227 0.000171557|
NB. |12|  1.1991e11   0.0168457   0.0236472   0.0125166|
NB. |13| 2.04781e11    0.105469  0.00541306     0.15654|
NB. |14| 3.39072e13       31.75   0.0152149     9.52918|
NB. |15| 1.79779e16        1221    0.250793     233.597|
NB. |16| 1.25256e17       35457     0.28186     13084.1|
NB. |17| 2.72968e16   2.89536e6    0.111938      390480|
NB. |18| 4.63074e15   5.62954e7    0.157135   4.39802e6|
NB. |19| 4.27497e12   4.22209e9    0.157682    8.6123e8|
NB. +--+-----------------------------------------------+
