-
Notifications
You must be signed in to change notification settings - Fork 0
/
powermethod.txt
42 lines (35 loc) · 1.9 KB
/
powermethod.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
this is version 1.0
Initial study of power method for a symmetrix matrix that returns dominant eigenvalue/eigenvector
current model: symmetric matrix. ( tested on some symmetric matrices )
checks for convergence
see below for todo list.
Instructions:
In a q session. Go to k. You can a free version at kx.com
(1) copy/paste variables.
(2) copy/paste while expression.
(3) Returns eigenvector and eigenvalue for dominant eigenvalue.
Choose a matrix 3X3 or 6x6. Dominant eigenvalue and eigenvector for the next two matrices were checked using excel.
A:((-1 2 -2);(-2 -6 3);(-2 -4 1))
A:((7 1 1 7 4 1);(4 4 4 4 4 4);(1 7 7 1 4 7);(7 1 1 7 4 1);(4 4 4 4 4 4);(1 7 7 1 4 7));
/ variables:
v:0.1,1_(#A)#0 / vector parameter used to compute eigenvalue. See that initial value is 1/10
vN:(#A)#10 / vector parameter used to compute eigenvalue. Add code to prevent these values and 'v' from becoming too large.
el: 2 / current eigenvalue
el2: 1 / previous eigenvalue
e:0.0000001 / error limit to test if eigenvalues have converged. epsilon.
ev: (#A)#1 / eigenvectors for this eigenvalue
iter:1
a:1 / boolean eigenvalues converges
b:1 / boolean iter max reached.
iterM:10000 / iter max
/ 3 lines of code.
while[1<a+b; vN:A(+/*)\:v;el2:el;el:(+/vN*v) % (+/v*v);ev:vN % el xexp iter;v:vN;a:e < abs(el2-el);iter+:1;b:iter < iterM];
$[iter=iterM;"Did not converge. Results are incorrect";"Converged in #iterations: ", $iter]
ev:ev % sqrt(+/ev*ev);R:(ev;el);::R
///To do
1. Test powermethod on various large symmetric matrix sizes. Ex: 1000x1000
2. Add code to prevent v and vN from having very large values. i.e. at some stage, v:%vN
///Notes
1. Power method isn't suitable to calculate all eigenvalues eigenvectors.
due to rounding off errors. Have not found any documentation identifying a deflation method that corrects
rounding off errors.