1function [x, info] = umfpack_solve (arg1, op, arg2, Control) 2%UMFPACK_SOLVE x = A\b or x = b/A 3% 4% Example: 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. 9% The Control argument is optional. 10% 11% See also umfpack, umfpack_make, umfpack_details, umfpack_report, 12% and umfpack_simple. 13 14% Copyright 1995-2007 by Timothy A. Davis. 15 16%------------------------------------------------------------------------------- 17% check inputs and get default control parameters 18%------------------------------------------------------------------------------- 19 20if (op == '\') 21 A = arg1 ; 22 b = arg2 ; 23elseif (op == '/') 24 A = arg2 ; 25 b = arg1 ; 26else 27 help umfack_solve 28 error ('umfpack_solve: unrecognized operator') ; 29end 30 31[m n] = size (A) ; 32if (m ~= n) 33 help umfpack_solve 34 error ('umfpack_solve: A must be square') ; 35end 36 37[m1 n1] = size (b) ; 38if ((op == '\' & n ~= m1) | (op == '/' & n1 ~= m)) %#ok 39 help umfpack_solve 40 error ('umfpack_solve: b has the wrong dimensions') ; 41end 42 43if (nargin < 4) 44 % get default controls 45 Control = umfpack ; 46end 47 48%------------------------------------------------------------------------------- 49% solve the system 50%------------------------------------------------------------------------------- 51 52if (op == '\') 53 54 if (~issparse (A)) 55 56 % A is not sparse, so just use MATLAB 57 x = A\b ; 58 info.nnz_in_L_plus_U = n^2 ; 59 60 elseif (n1 == 1 & ~issparse (b)) %#ok 61 62 % the UMFPACK '\' requires b to be a dense column vector 63 [x info] = umfpack (A, '\', b, Control) ; 64 65 else 66 67 % factorize with UMFPACK and do the forward/back solves in MATLAB 68 [L, U, P, Q, R, info] = umfpack (A, Control) ; 69 x = Q * (U \ (L \ (P * (R \ b)))) ; 70 71 end 72 73else 74 75 if (~issparse (A)) 76 77 % A is not sparse, so just use MATLAB 78 x = b/A ; 79 info.nnz_in_L_plus_U = n^2 ; 80 81 elseif (m1 == 1 & ~issparse (b)) %#ok 82 83 % the UMFPACK '\' requires b to be a dense column vector 84 [x info] = umfpack (b, '/', A, Control) ; 85 86 else 87 88 % factorize with UMFPACK and do the forward/back solves in MATLAB 89 % this mimics the behavior of x = b/A, except for the row scaling 90 [L, U, P, Q, R, info] = umfpack (A.', Control) ; 91 x = (Q * (U \ (L \ (P * (R \ (b.')))))).' ; 92 93 % an alternative method: 94 % [L, U, P, Q, r] = umfpack (A, Control) ; 95 % x = (R \ (P' * (L.' \ (U.' \ (Q' * b.'))))).' ; 96 97 end 98 99end 100