File: gee_its_simple.m

package info (click to toggle)
suitesparse 1%3A5.12.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 176,720 kB
  • sloc: ansic: 1,193,914; cpp: 31,704; makefile: 6,638; fortran: 1,927; java: 1,826; csh: 765; ruby: 725; sh: 529; python: 333; perl: 225; sed: 164; awk: 35
file content (38 lines) | stat: -rw-r--r-- 1,267 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
function [x, rcnd] = gee_its_simple (A, b)
%GEE_ITS_SIMPLE solves A*x=b using a Gaussian Elimination Example (it's simple!)
% For details on the algorithm used (Gaussian elimination with partial
% pivoting), see gee_its_simple_factorize, gee_its_simple_forwardsolve,
% and gee_its_simple_backsolve.
%
% Example:
%
%   x = gee_its_simple (A,b) ;
%   [x,rcnd] = gee_its_simple (A,b) ;
%
%   % which is the same as:
%   x = A\b ;
%
%   % or using LU:
%   [L U p] = lu (A) ;
%   x = U \ (L \ (b (p,:))) ;
%   rcnd = min (abs (diag (U))) / max (abs (diag (U))) ;
%
% See also: lu, mldivide, rcond, gee_its_short

% Copyright 2007, Timothy A. Davis, http://www.suitesparse.com

% check inputs
if (nargin ~= 2 | nargout > 2)                                              %#ok
    error ('Usage: [x,rcnd] = gee_its_simple (A,b)') ;
end

% ensure A is square, and that A and b have the same number of rows
gee_its_simple_check (A, 'A', b) ;

% LU factorization, using Gaussian Elimination with partial pivoting, same as
% [L,U,p] = lu (A) ; rcnd = rcond (A) ; except return L and U in one matrix LU.
[LU p rcnd] = gee_its_simple_factorize (A) ;

% forward/backsolve, same as x = U \ (L \ b (p,:))
x = gee_its_simple_backsolve (LU, gee_its_simple_forwardsolve (LU, b (p,:))) ;