40 DEFUN (luinc, args, nargout,
42 @deftypefn {Built-in Function} {[@var{L}, @var{U}, @var{P}, @var{Q}] =} luinc (@var{A}, '0')\n\
43 @deftypefnx {Built-in Function} {[@var{L}, @var{U}, @var{P}, @var{Q}] =} luinc (@var{A}, @var{droptol})\n\
44 @deftypefnx {Built-in Function} {[@var{L}, @var{U}, @var{P}, @var{Q}] =} luinc (@var{A}, @var{opts})\n\
45 @cindex LU decomposition\n\
46 Produce the incomplete LU@tie{}factorization of the sparse matrix @var{A}.\n\
47 Two types of incomplete factorization are possible, and the type\n\
48 is determined by the second argument to @code{luinc}.\n\
50 Called with a second argument of @qcode{'0'}, the zero-level incomplete\n\
51 LU@tie{}factorization is produced. This creates a factorization of @var{A}\n\
52 where the position of the non-zero arguments correspond to the same\n\
53 positions as in the matrix @var{A}.\n\
55 Alternatively, the fill-in of the incomplete LU@tie{}factorization can\n\
56 be controlled through the variable @var{droptol} or the structure\n\
57 @var{opts}. The @sc{umfpack} multifrontal factorization code by Tim A.\n\
58 Davis is used for the incomplete LU@tie{}factorization, (availability\n\
59 @url{http://www.cise.ufl.edu/research/sparse/umfpack/})\n\
61 @var{droptol} determines the values below which the values in the\n\
62 LU@tie{} factorization are dropped and replaced by zero. It must be a\n\
63 positive scalar, and any values in the factorization whose absolute value\n\
64 are less than this value are dropped, expect if leaving them increase the\n\
65 sparsity of the matrix. Setting @var{droptol} to zero results in a complete\n\
66 LU@tie{}factorization which is the default.\n\
68 @var{opts} is a structure containing one or more of the fields\n\
72 The drop tolerance as above. If @var{opts} only contains @code{droptol}\n\
73 then this is equivalent to using the variable @var{droptol}.\n\
76 A logical variable flagging whether to use the modified incomplete\n\
77 LU@tie{} factorization. In the case that @code{milu} is true, the dropped\n\
78 values are subtracted from the diagonal of the matrix @var{U} of the\n\
79 factorization. The default is @code{false}.\n\
82 A logical variable that flags whether zero elements on the diagonal of\n\
83 @var{U} should be replaced with @var{droptol} to attempt to avoid singular\n\
84 factors. The default is @code{false}.\n\
87 Defines the pivot threshold in the interval [0,1]. Values outside that\n\
91 All other fields in @var{opts} are ignored. The outputs from @code{luinc}\n\
92 are the same as for @code{lu}.\n\
94 Given the string argument @qcode{\"vector\"}, @code{luinc} returns the\n\
95 values of @var{p} @var{q} as vector values.\n\
96 @seealso{sparse, lu}\n\
99 int nargin = args.length ();
104 else if (nargin < 2 || nargin > 3)
105 error (
"luinc: incorrect number of arguments");
108 bool zero_level =
false;
112 double droptol = -1.;
115 if (args(1).is_string ())
117 if (args(1).string_value () ==
"0")
120 error (
"luinc: unrecognized string argument");
122 else if (args(1).is_map ())
139 milu = (val == 0. ?
false :
true);
147 udiag = (val == 0. ?
false :
true);
155 if (thresh.
nelem () == 1)
158 thresh(1) = thresh(0);
160 else if (thresh.
nelem () != 2)
162 error (
"luinc: expecting 2-element vector for thresh");
169 error (
"luinc: OPTS must be a scalar structure");
174 droptol = args(1).double_value ();
178 std::string tmp = args(2).string_value ();
182 if (tmp.compare (
"vector") == 0)
185 error (
"luinc: unrecognized string argument");
191 error (
"luinc: zero-level factorization not implemented");
195 if (args(0).type_name () ==
"sparse matrix")
213 SparseLU fact (sm, Qinit, thresh,
false,
true, droptol,
233 SparseLU fact (sm, Qinit, thresh,
false,
true, droptol,
239 retval(2) = fact.
Pr_vec ();
241 retval(2) = fact.
Pr_mat ();
255 SparseLU fact (sm, Qinit, thresh,
false,
false, droptol,
262 retval(3) = fact.
Pc_vec ();
263 retval(2) = fact.
Pr_vec ();
267 retval(3) = fact.
Pc_mat ();
268 retval(2) = fact.
Pr_mat ();
282 else if (args(0).type_name () ==
"sparse complex matrix")
285 args(0).sparse_complex_matrix_value ();
302 droptol, milu, udiag);
323 droptol, milu, udiag);
328 retval(2) = fact.
Pr_vec ();
330 retval(2) = fact.
Pr_mat ();
345 droptol, milu, udiag);
351 retval(3) = fact.
Pc_vec ();
352 retval(2) = fact.
Pr_vec ();
356 retval(3) = fact.
Pc_mat ();
357 retval(2) = fact.
Pr_mat ();
372 error (
"luinc: matrix A must be sparse");