Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.61 KB | None | 0 0
  1. function [ B ] = inv_by_czarek( A )
  2. %[ B ] = inv_by_czarek( A ) The function calculates inverse of matrix A
  3. %using double Gauss elimintation concept
  4.  
  5. [r, c] = size(A);
  6.  
  7. if (r == c)
  8.    
  9.     Z=[A,eye(r)];
  10.    
  11.     for i=1:c-1;
  12.         for j=i+1:r;
  13.             Z(j,:)=Z(j,:)-Z(j,i)/Z(i,i)*Z(i,:);
  14.         end;
  15.     end;
  16.    
  17.     for i=c:-1:2;
  18.         for j=i-1:-1:1;
  19.             Z(j,:)=Z(j,:)-Z(j,i)/Z(i,i)*Z(i,:);
  20.         end
  21.     end
  22.     B=Z;
  23.    
  24. else
  25.     disp('Dear user of my function,');
  26.     disp ('you should be so smart enough to know that the matrix A must be sqare one!');
  27.    
  28. end;
  29.  
  30. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement