Advertisement
desdemona

cramer

Mar 27th, 2013
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.36 KB | None | 0 0
  1. function x = cramer(A, b)
  2.  
  3. % cramer  Solve the system Ax=b.
  4. % The matrix A is square and invertible.
  5. %
  6. % x = cramer(A, b) solves the square system Ax = b.
  7.  
  8. [m, n] = size(A);
  9. if m ~= n
  10.   error('Matrix is not square.')
  11. end
  12. if det(A) == 0
  13.   error('Matrix is singular.')
  14. end
  15. for j = 1:n
  16.   B = A;
  17.   B(:, j) = b;
  18.   x(j) = det(B) / det(A);
  19. end
  20. x = x';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement