Newsgroups: comp.lang.apl
Path: watmath!watserv2.uwaterloo.ca!torn!cs.utexas.edu!zaphod.mps.ohio-state.edu!howland.reston.ans.net!usc!elroy.jpl.nasa.gov!ufo!jato!csi!sam
From: sam@csi.jpl.nasa.gov (Sam Sirlin)
Subject: Re: Matrix Inverse in APL2
Message-ID: <1993Jan18.191141.6303@csi.jpl.nasa.gov>
Originator: sam@kalessin
Sender: usenet@csi.jpl.nasa.gov (Network Noise Transfer Service)
Nntp-Posting-Host: kalessin
Organization: Jet Propulsion Laboratory, Pasadena, CA
References: <726871483snz@apl.demon.co.uk> <1476@kepler1.rentec.com> <1993Jan15.183816.29350@csi.jpl.nasa.gov> <1993Jan16.105448.26408@csus.edu>
Date: Mon, 18 Jan 1993 19:11:41 GMT
Lines: 117


In article <1993Jan16.105448.26408@csus.edu>, emclean@sfsuvax1.sfsu.edu (Emmett McLean) writes:

|>    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 ?

Well certainly! I just stuck junk togther till it worked, then did
5!:5 to get the linear rep. 

|>    dif1 =. '(=/~i.y.) - (js_inv (+/ .*) hilbert) y.':11

|>    row_norm1 =. '; >./ (+/)"1 dif1 y.':11 

Hmm, are you forgetting to take absolute values? Or am I just blind.
Withouut them this isn't really much of a norm (though the results do
look similar when I put | in).

Here's a more usual matrix norm approach:

NB. euclidian matrix norm (just the root of the sum of squares)
NB. you could do the spectral norm, but then need e. values
   n_euclid=. '(+/ , x.^2)^0.5' : 11
   unit =/~@(i.@])

   test_inv=.  'n_euclid@(unit@] - x.f. @] +/ .* hilbert@])' :1
   compare=. 'y., (js_inv test_inv y.), my_inv test_inv y.' : 11

NB. a list of order, js error, formula error
   data=. compare &.> <"0 (1+i. 30)
   >data
 1           0           0
 2 3.19505e_14           0
 3 4.41857e_12           0
 4  8.00038e_9 5.68434e_14
 5  1.68636e_5 3.63798e_12
 6  0.00315133  1.4552e_11
 7     11.4474  5.2088e_10
 8      4311.5  5.16534e_8
 9   3.37378e6  2.73143e_7
10   2.75089e8  2.17958e_5
11   4.86893e9  0.00137716
12  6.93806e11   0.0597765
13  2.19107e10      3.2391
14  3.57005e14      208.18
15  2.07229e16     8907.56
16   2.5655e16      215651
17  5.42727e12   6.71307e6
18  6.14095e13   1.92173e8
19  2.84372e14   6.45163e9
20  7.89463e13  2.53422e11
21  1.93163e14  1.36815e13
22  2.50337e14  3.21142e14
23  5.71018e14  1.30671e16
24  3.10202e16  3.93668e17
25  9.21075e14  1.42975e19
26  3.67628e16  5.75795e20
27  3.66141e16  1.46293e22
28  1.42525e16  5.30575e23
29  5.41024e15  1.64195e25
30  4.08852e16  4.66684e26

So the formula is better than the system inverse for quite a while,
then craps out at about order 22. Of course I'd say both were useless
long before then. I'm not sure what you wan't explained, but it's not
surprising that you can't represent the exact inverse in even double
precision. Perhaps you're refering to the difference between left and
right results? Adding the right inverse test:

test_invr=.  'n_euclid@(unit@] - hilbert@] +/ .* x.f. @]) ' :1
compare2=. 'y., (js_inv test_inv y.), (js_inv test_invr y.), (my_inv
test_\
inv y.), my_inv test_invr y.' : 11

order         js_inv                my_inv
         left     right       left        right

 1           0           0           0           0
 2 3.19505e_14 2.36037e_15           0           0
 3 4.41857e_12 1.26935e_13           0           0
 4  8.00038e_9 1.75494e_12 5.68434e_14 5.68434e_14
 5  1.68636e_5  3.46524e_9 3.63798e_12 3.63798e_12
 6  0.00315133  7.93292e_9  1.4552e_11  1.4552e_11
 7     11.4474  3.00677e_5  5.2088e_10  5.2088e_10
 8      4311.5 0.000223377  5.16534e_8  5.16534e_8
 9   3.37378e6   0.0248642  2.73143e_7  2.73143e_7
10   2.75089e8     1.40941  2.17958e_5  2.17958e_5
11   4.86893e9     1.41316  0.00137716  0.00137716
12  6.93806e11     1.41593   0.0597765   0.0597765
13  2.19107e10     2.00005      3.2391      3.2391
14  3.57005e14     2.02023      208.18      208.18
15  2.07229e16     2.45754     8907.56      8787.9
...

It seems that the system function does better as right inverse than a
left inverse. Off the top of my head, this could be because of the way
the matrix decomposition proceeds or perhaps is influenced by the
order in which the inner products are taken...

-- 
Sam Sirlin
Jet Propulsion Laboratory         sam@kalessin.jpl.nasa.gov

