1
1
function x = umfpack_solve (arg1, op, arg2, Control)
2
%UMFPACK_SOLVE x = A\b or x = b/A
4
% x = umfpack_solve (A, '\', b, Control)
5
% x = umfpack_solve (b, '/', A, Control)
5
% x = umfpack_solve (A, '\', b, Control)
6
% x = umfpack_solve (b, '/', A, Control)
7
8
% Computes x = A\b, or b/A, where A is square. Uses UMFPACK if A is sparse.
8
9
% The Control argument is optional.
10
% See also umfpack, umfpack_make, umfpack_details, umfpack_report,
11
% See also umfpack, umfpack2, umfpack_make, umfpack_details, umfpack_report,
11
12
% and umfpack_simple.
13
% UMFPACK Version 5.0, Copyright (c) 1995-2006 by Timothy A. Davis.
14
% All Rights Reserved. Type umfpack_details for License.
14
% Copyright 1995-2007 by Timothy A. Davis.
16
16
%-------------------------------------------------------------------------------
17
17
% check inputs and get default control parameters
37
37
[m1 n1] = size (b) ;
38
if ((op == '\' & n ~= m1) | (op == '/' & n1 ~= m))
38
if ((op == '\' & n ~= m1) | (op == '/' & n1 ~= m)) %#ok
40
40
error ('umfpack_solve: b has the wrong dimensions') ;
47
47
%-------------------------------------------------------------------------------
55
55
% A is not sparse, so just use MATLAB
58
elseif (n1 == 1 & ~issparse (b))
58
elseif (n1 == 1 & ~issparse (b)) %#ok
60
60
% the UMFPACK '\' requires b to be a dense column vector
61
x = umfpack (A, '\', b, Control) ;
61
x = umfpack2 (A, '\', b, Control) ;
65
65
% factorize with UMFPACK and do the forward/back solves in MATLAB
66
[L, U, P, Q, R] = umfpack (A, Control) ;
66
[L, U, P, Q, R] = umfpack2 (A, Control) ;
67
67
x = Q * (U \ (L \ (P * (R \ b)))) ;
75
75
% A is not sparse, so just use MATLAB
78
elseif (m1 == 1 & ~issparse (b))
78
elseif (m1 == 1 & ~issparse (b)) %#ok
80
80
% the UMFPACK '\' requires b to be a dense column vector
81
x = umfpack (b, '/', A, Control) ;
81
x = umfpack2 (b, '/', A, Control) ;
85
85
% factorize with UMFPACK and do the forward/back solves in MATLAB
86
86
% this mimics the behavior of x = b/A, except for the row scaling
87
[L, U, P, Q, R] = umfpack (A.', Control) ;
87
[L, U, P, Q, R] = umfpack2 (A.', Control) ;
88
88
x = (Q * (U \ (L \ (P * (R \ (b.')))))).' ;
90
90
% an alternative method:
91
% [L, U, P, Q, r] = umfpack (A, Control) ;
91
% [L, U, P, Q, r] = umfpack2 (A, Control) ;
92
92
% x = (R \ (P' * (L.' \ (U.' \ (Q' * b.'))))).' ;