Advertisement
tadejpetric

Untitled

Jan 10th, 2021
3,745
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Octave 0.85 KB | None | 0 0
  1. function x = potencna(A, zac, tol)
  2.   rayleigh = @(x) x'*A(x)/(x' * x);
  3.   x.vrednosti = [rayleigh(zac)];
  4.   x.vektorji = [zac];
  5.   k = 1;
  6.   while norm(A(x.vektorji(:, k)) - x.vrednosti(k)*x.vektorji(:, k)) >= tol
  7.     k = k+1;
  8.     x.vektorji(:,k) = A(x.vektorji(:, k-1));
  9.     x.vektorji(:,k) = x.vektorji(:, k)/norm(x.vektorji(:, k));
  10.     x.vrednosti(k) = rayleigh(x.vektorji(:, k));
  11.     if k == 501
  12.       break
  13.     endif
  14.      
  15.   endwhile
  16.  
  17. endfunction
  18.  
  19.  
  20.  
  21. function x = hotelling(A, zac, hotel_steps)
  22.   u = potencna(A, zac, eps);
  23.   x.vrednosti(1) = u.vrednosti(end);
  24.   x.vektorji(:,1) = u.vektorji(:,end);
  25.   for i = 2:hotel_steps+1
  26.     A = @(y) A(y) - x.vrednosti(i-1) * x.vektorji(:,i-1)*x.vektorji(:,i-1)'*y;
  27.     u = potencna(A, zac, eps);
  28.     x.vrednosti(i) = u.vrednosti(501);
  29.     x.vektorji(:,i) = u.vektorji(:,501);
  30.   endfor
  31. endfunction
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement