Mercurial > matrix-functions
view toolbox/gj.m @ 7:e0817ccb2834 draft
Add square root matrix function file, rename atom at funm_files, modify old toolbox to run it inside GNU Octave.
added funm_files/fun_atom.m
added sqrtm2.m
added toolbox/gecp.m
toolbox/see.m: comment wrong call to subplot
toolbox/tmtdemo.m: add a cast to double, as eig does not admit bool matrix input
removed funm_files/funm_atom.m
author | Antonio Pino Robles <data.script93@gmail.com> |
---|---|
date | Tue, 26 May 2015 18:14:54 +0200 |
parents | 8f23314345f4 |
children |
line wrap: on
line source
function x = gj(A, b, piv) %GJ Gauss-Jordan elimination to solve Ax = b. % x = GJ(A, b, PIV) solves Ax = b by Gauss-Jordan elimination, % where A is a square, nonsingular matrix. % PIV determines the form of pivoting: % PIV = 0: no pivoting, % PIV = 1 (default): partial pivoting. n = max(size(A)); if nargin < 3, piv = 1; end for k=1:n if piv % Partial pivoting (below the diagonal). [colmax, i] = max( abs(A(k:n, k)) ); i = k+i-1; if i ~= k A( [k, i], : ) = A( [i, k], : ); b( [k, i] ) = b( [i, k] ); end end irange = [1:k-1 k+1:n]; jrange = k:n; mult = A(irange,k)/A(k,k); % Multipliers. A(irange, jrange) = A(irange, jrange) - mult*A(k, jrange); b(irange) = b(irange) - mult*b(k); end x = diag(diag(A))\b;