Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function x = potencna(A, zac, tol)
- rayleigh = @(x) x'*A(x)/(x' * x);
- x.vrednosti = [rayleigh(zac)];
- x.vektorji = [zac];
- k = 1;
- while norm(A(x.vektorji(:, k)) - x.vrednosti(k)*x.vektorji(:, k)) >= tol
- k = k+1;
- x.vektorji(:,k) = A(x.vektorji(:, k-1));
- x.vektorji(:,k) = x.vektorji(:, k)/norm(x.vektorji(:, k));
- x.vrednosti(k) = rayleigh(x.vektorji(:, k));
- if k == 501
- break
- endif
- endwhile
- endfunction
- function x = hotelling(A, zac, hotel_steps)
- u = potencna(A, zac, eps);
- x.vrednosti(1) = u.vrednosti(end);
- x.vektorji(:,1) = u.vektorji(:,end);
- for i = 2:hotel_steps+1
- A = @(y) A(y) - x.vrednosti(i-1) * x.vektorji(:,i-1)*x.vektorji(:,i-1)'*y;
- u = potencna(A, zac, eps);
- x.vrednosti(i) = u.vrednosti(501);
- x.vektorji(:,i) = u.vektorji(:,501);
- endfor
- endfunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement