Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 0.68 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. function x = PR_Inv(A)
  2.         % Functia care calculeaza inversa matricii A folosind factorizari Gram-Schmidt
  3.         % Se va inlocui aceasta linie cu descrierea algoritmului de inversare
  4.  
  5.         N = length(A);
  6.         for i = 1:N
  7.                 R(i, i) = norm(A(1:N, i));
  8.                 Q(1:N, i) = A(1:N, i) / R(i, i);
  9.                 for j = i+1:N
  10.                         R(i, j) = Q(1:N, i)' * A(1:N, j);
  11.                         A(1:N, j) = A(1:N, j) - Q(1:N, i) * R(i, j);
  12.                 endfor
  13.         endfor
  14.  
  15.         [N, N] = size(R);
  16.         I = eye(N);
  17.         for k = 1:N
  18.                 x = zeros(N, 1);
  19.                 b(1:N) = I(:, k);
  20.                 x(N) = b(N) / R(N, N);
  21.                 for i = N-1:-1:1
  22.                         x(i) = ( b(i) - R(i, i+1:N)*x(i+1:N))/R(i, i);
  23.                 endfor
  24.                 Rinv(1:N, 1) = x;
  25.         endfor
  26.  
  27.         for i = 1:N
  28.                 Qinv = Q';
  29.         endfor
  30.  
  31.         B = Qinv * Rinv;
  32.  
  33. endfunction