Advertisement
bolek117

[ATiNM] Eigen vectors

Apr 1st, 2015
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.83 KB | None | 0 0
  1. clc
  2. clear all
  3. close all
  4.  
  5. eps = 0.0005;
  6.  
  7. x = ones(3,1);
  8. %A = [3 2 1; 2 8 4; 1 4 5];
  9.  A = [1 2 3; 2 4 1; 3 1 6];
  10.  
  11. V = A * x;  % Move to upper scope
  12.  
  13. x_normalized = x;
  14. max_val = 1e99;
  15. max_val_old = 0;
  16. diff = 1e99;
  17.  
  18. i = 0;
  19. while true,
  20.     diff = abs(abs(max_val) - abs(max_val_old));
  21.    
  22.     if abs(diff) < eps,
  23.         break
  24.     end
  25.    
  26.     %disp('**************');
  27.     %fprintf('***   %d   ***\n', i);
  28.     %disp('**************');
  29.    
  30.     old_v = V;
  31.     V = A * x_normalized;
  32.    
  33.     max_val_old = max_val;
  34.     max_val = max(V, [], 1)   ;
  35.    
  36.     x_normalized = V / max_val;
  37.     i = i+1;
  38. end
  39.  
  40. disp('*** Task 1 ***');
  41. i
  42. eigen_value = max_val
  43. eigen_vector = V / max_val
  44.  
  45. disp('*** Task 2 ***');
  46.  
  47. V_1 = eigen_vector / sqrt(sum(eigen_vector, 1))
  48. V1_V1T = V_1 * (V_1')
  49.  
  50. a_prim = A - eigen_value * V1_V1T
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement