NB. A cool use of eigen vectors and values -- recursion
NB. Adapted from Section 6.2 of Gilbert Strang,
NB. Introduction to Linear Algebra
NB. Preliminaries
clean =: * *@| NB. numbers with 2^_44 > | are replaced by 0
mp =: +/ . * NB. matrix product
NB. below, square matrix x to integer power y
mpwr =: ( 4 : 'x mp^:y =i.#x' )"2 0
NB. The recursion ( (1+k) { u ) -: A mp k { u
NB. u is a matrix with the same number of columns
NB. as square matrix A and at least 2 rows
]A =: 1 1,.1 0 NB. used for Fibonnaci recursion
1 1
1 0
]lambda =: 2 %~ (1+%:5),1-%:5 NB. eigenvalues of A
1.61803 _0.618034
]Lambda =: lambda * =i.# lambda NB. eigenvalues on diagonal
1.61803 0
0 _0.618034
]S =: 2 2 $ lambda,1 1 NB. columns are eigenvectors
1.61803 _0.618034
1 1
(A mp S) -: lambda *&.|: S NB. test claimed eigen vectors, values
1
]u0 =: 1 0 NB. first row of matrix u
1 0
]nr =: 7 NB. number of rows in u
7
]u =: (A mpwr i. nr) mp"2 1 u0 NB. produce matrix u
1 0
1 1
2 1
3 2
5 3
8 5
13 8
NB. Rows obey Fibonnaci recursion, observe second column
(}. u) -: }: A mp&.|: u NB. test the "A" recursion in the rows of u
1
NB. You can produce u using the eigen values and vectors of A
u -: clean ( S mp"2 (Lambda mpwr i. nr) mp"2 S mpwr _1 ) mp"2 1 u0
1
NB. More simply:
c =: (S mpwr _1) mp u0
u -: clean S mp"2 1 c *"1 lambda ^"1 0 i. nr
1
NB. Conclusion
NB. Above will work if n by n matrix A has n linearly independent
NB. eigenvectors. You supply A u0 nr>1 lambda and S .
--Kip Murray
On 10/3/2013 1:47 PM, Raul Miller wrote:
This would be a lot more readable, to me, if you supplied a J
implementation that matched the informal math notation (which is easy
to read for people that mostly already know what you were going to
say).
Thanks,
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm