## Attachment 'jacobiMcIntyreSomeCode.txt'

NB. Some (obsolete version of J) code from article "Jacobi's Method for
NB. Eigenvalues: an Illustration of J" by Donald McIntyre in the January,
NB. 1993 issue of Vector (Vol. 9, No. 3).

NB. From page 127:
setrl=. 9!:1                   NB. Set Random Link
ut=. ,@(</~@i.)@#              NB. Upper Triangle
pt=. (, i. >./@(ut # ,))@|     NB. Pivot in Triangle
pm=. <.@(pt % #) , # | pt      NB. Pivot in Matrix
pv=. {~ <@pm                   NB. Pivot
pa=. 0 0&{ ; ] ; |. ; 1 1&{    NB. Permutations for Amend
ia=. pa@pm { i.@\$              NB. Indices for Amend
pt=. [: (, i. [: >./ ut # ,) | NB. Pivot in Triangle - more modern J
amend=. ia@]}

NB. Define "y" as in article since random number generator differs.
y=. _37 25 _5 3 _29 _46,17 17 43 _12 1 33,_47 _45 2 17 _50 _12,_44 _9 18 8 43 34,2 _41 15 _9 20 41,:26 _24 _46 23 _18 13

NB. From page 128:
ip=. +/ .*                              NB. inner product
write=. 1!:2&2                          NB. write to screen
diag=. (<0 1)&|:                        NB. matrix diagonal
uf=. -:@-/@(pm{diag)                    NB. u function
rss=. %:@+/@*:                          NB. sq rt of sum of sqs
sign=. >:&0 - <&0                       NB. sign of the sine
cosf=. %:@((vf + |@uf) % +:@vf)         NB. cosine function
sinf=. sign@uf * -@pf % +: @(vf * cosf) NB. sine function

NB. Much of the code before this point will work in a contemporary (ca. 2010)
NB. version of J.  However, the following method of function definition will
NB. fail.  Also, the various loop constructs shown here no longer exist in
NB. the language.

maxit=. 20
s0=. <'it=. 0 { I=. Q=. =/! i.#R=. y'
s0=. <'it=. 0 { I=. Q=. =/! i.#R=. y.'
s1=. <'loop) \$.=. >(end;\$.){~ x.<|p=. -pv R'
s2=. <'v=. %: +/*~p,u=. -: -/ (pm R){ diag R'
se=. <'sin=. (sign u)*p%+:v* cos=. %: (v+|u)%+:v'
s3=. <'sin=. (sign u)*p%+:v* cos=. %: (v+|u)%+:v'
s4=. <'\$.=. >(end;\$.){~ *./0~:-.-|sin,cos'
s5=. <'r=. ((cos,-sin),sin,cos) (ia R)} I'
s6=. <'Q=. Q ip |:r [ R=. r ip R ip |:r'
s7=. <'\$.=. >(loop;\$.){~ maxit<it=. it+1'
s8=. <'write ''Number of further iterations or 0?'''
s9=. <'\$.=. >(loop;end){~ maxit<it=. it-readkb 1'
s10=. <'end) R,:Q'
jacobi=. '' : (s0,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10)

NB. Since the above attempt at function definition fails, here's what
NB. the code would look like (defined as an anonymous noun).

0 : 0
it=. 0 { I=. Q=. =/! i.#R=. y.
loop) \$.=. >(end;\$.){~ x.<|p=. -pv R
v=. %: +/*~p,u=. -: -/ (pm R){ diag R
sin=. (sign u)*p%+:v* cos=. %: (v+|u)%+:v
\$.=. >(end;\$.){~ *./0~:-.-|sin,cos
r=. ((cos,-sin),sin,cos) (ia R)} I
Q=. Q ip |:r [ R=. r ip R ip |:r
\$.=. >(loop;\$.){~ maxit<it=. it+1
write 'Number of further iterations or 0?'
end) R,:Q
)

## Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
• [get | view] (2010-01-16 03:53:05, 347.1 KB) [[attachment:JacobiMethodEigenvaluesByMcIntyre125_Vec199301_66.jpg]]
• [get | view] (2010-01-16 04:04:51, 305.3 KB) [[attachment:JacobiMethodEigenvaluesByMcIntyre126_Vec199301_66.jpg]]
• [get | view] (2010-01-16 04:06:39, 136.9 KB) [[attachment:JacobiMethodEigenvaluesByMcIntyre127_Vec199301_66.jpg]]
• [get | view] (2010-01-16 04:12:17, 297.4 KB) [[attachment:JacobiMethodEigenvaluesByMcIntyre128_Vec199301_66.jpg]]
• [get | view] (2010-01-16 04:08:12, 229.9 KB) [[attachment:JacobiMethodEigenvaluesByMcIntyre129_Vec199301_66.jpg]]
• [get | view] (2010-01-16 04:08:42, 233.9 KB) [[attachment:JacobiMethodEigenvaluesByMcIntyre130_Vec199301_66.jpg]]
• [get | view] (2010-01-16 04:09:59, 228.2 KB) [[attachment:JacobiMethodEigenvaluesByMcIntyre131_Vec199301_66.jpg]]
• [get | view] (2010-01-16 04:10:50, 212.9 KB) [[attachment:JacobiMethodEigenvaluesByMcIntyre132_Vec199301_66.jpg]]
• [get | view] (2010-01-16 04:11:26, 281.3 KB) [[attachment:JacobiMethodEigenvaluesByMcIntyre133_Vec199301_66.jpg]]
• [get | view] (2010-01-16 19:22:16, 2.8 KB) [[attachment:jacobiMcIntyreSomeCode.txt]]
• [get | view] (2010-01-16 04:20:45, 0.8 KB) [[attachment:p127Code.txt]]
• [get | view] (2010-01-16 04:21:09, 1.8 KB) [[attachment:p128Code.txt]]