{"id":492,"date":"2017-09-14T12:43:57","date_gmt":"2017-09-14T15:43:57","guid":{"rendered":"http:\/\/www.professores.uff.br\/diomarcesarlobao\/?page_id=492"},"modified":"2017-09-14T12:43:57","modified_gmt":"2017-09-14T15:43:57","slug":"gauselim-m","status":"publish","type":"page","link":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/gauselim-m\/","title":{"rendered":"gauselim.m"},"content":{"rendered":"<pre>function [x, err] = gauselim(A, b)\r\n% Gaussian Elimination routine\r\n%\r\n% USAGE:   [x, err] = gauselim(A, b)\r\n%  where   A = square coefficient matrix, size n X n\r\n%          b = single RHS column vector, size n X 1\r\n%          x = solution column vector, size n X 1\r\n%        err = error code:\r\n%                = 0 = no error\r\n%                = 1 = singular matrix detected\r\n%                = 2 = not a square matrix\r\n\r\nerr = 0;\r\n\r\n% check that input is legal\r\n[n,m] = size(A);\r\nif n ~= m\r\n  disp('Error in gauselim: Matrix must be square.')\r\n  err = 2; return\r\nend\r\n\r\n%set up space for solution vector\r\nx = zeros(size(b));\r\n\r\n% form augmented matrix by adding b to last column of A\r\nm = n+1; A(:,m) = b;\r\n\r\n% FORWARD ELIMINATION\r\n\r\nfor k = 1:n-1\r\n\r\n  [A, err] = gepivot(A, k);   % partial pivoting\r\n\r\n  if err ~= 0\r\n     disp('Matrix is singular'); return\r\n  end\r\n\r\n  for i = k+1:n\r\n    term = A(i,k)\/A(k,k);\r\n    for j = k+1:m\r\n       A(i,j) = A(i,j) - term*A(k,j);\r\n    end\r\n  end\r\nend\r\n\r\n% BACK SUBSTITUTION\r\nif A(n,n) == 0\r\n     err = 1; disp('Matrix is singular'); return\r\nend\r\n\r\nx(n) = A(n,m)\/A(n,n);\r\nfor i = n-1:-1:1\r\n   sum = 0;\r\n   for j = i+1:n\r\n      sum = sum + A(i,j)*x(j);\r\n   end\r\n   x(i) = (A(i,m) - sum) \/ A(i,i);\r\nend\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>function [x, err] = gauselim(A, b) % Gaussian Elimination routine % % USAGE: [x, err] = gauselim(A, b) % where A = square coefficient matrix, size n X n % b = single RHS column vector, size n X 1 % x = solution column vector, size n X 1 % err = error code: [&hellip;]<\/p>\n","protected":false},"author":22,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[],"tags":[],"class_list":["post-492","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/492","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/users\/22"}],"replies":[{"embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/comments?post=492"}],"version-history":[{"count":1,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/492\/revisions"}],"predecessor-version":[{"id":493,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/492\/revisions\/493"}],"wp:attachment":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/media?parent=492"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/categories?post=492"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/tags?post=492"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}