I'm trying to solve a sparse matrix equation of the form A*x = b, where A is a known square, sparse matrix, and b is a known column vector, and x is the column vector to be determined. Standard MATLAB syntax for solving this is:
x = A\b;
Behind the scenes, the \
operator is shorthand for "use whatever algorithm seems best to solve this equation." MATLAB accordingly chooses what it thinks will be an optimal algorithm for solving that equation and solves the system of equations using that algorithm.
While this one-symbol-works-for-all-cases approach has worked great for me in the past, I need to know which algorithm is being used to solve my system of equations. Does anyone know how I could find this out? Perhaps there is a way to tell MATLAB to print any/all functions that get called, with indentation for nested calls?
I think that you shoul use spparms, from a matlab forum
help spparms
spparms - Set parameters for sparse matrix routines
This MATLAB function sets one or more of the tunable parameters used in the
sparse routines.
spparms('key',value)
spparms
values = spparms
[keys,values] = spparms
spparms(values)
value = spparms('key')
spparms('default')
spparms('tight')
Reference page for spparms
See also chol, colamd, lu, qr, symamd
like this
>> A = sparse(rand(10).*round(rand(10)-0.2));
spparms('spumoni',2)
A\rand(10,1)
sp\: bandwidth = 9+1+7.
sp\: is A diagonal? no.
sp\: is band density (0.27) > bandden (0.50) to try banded solver? no.
sp\: is A triangular? no.
sp\: is A morally triangular? no.
sp\: is A a candidate for Cholesky (symmetric, real positive diagonal)? no.
sp\: use Unsymmetric MultiFrontal PACKage with automatic reordering.
UMFPACK V5.4.0 (May 20, 2009), Control:
Matrix entry defined as: double
Int (generic integer) defined as: UF_long
0: print level: 2
1: dense row parameter: 0.2
"dense" rows have > max (16, (0.2)*16*sqrt(n_col) entries)
2: dense column parameter: 0.2
"dense" columns have > max (16, (0.2)*16*sqrt(n_row) entries)
3: pivot tolerance: 0.1
4: block size for dense matrix kernels: 32
5: strategy: 0 (auto)
6: initial allocation ratio: 0.7
7: max iterative refinement steps: 2
12: 2-by-2 pivot tolerance: 0.01
13: Q fixed during numerical factorization: 0 (auto)
14: AMD dense row/col parameter: 10
"dense" rows/columns have > max (16, (10)*sqrt(n)) entries
Only used if the AMD ordering is used.
15: diagonal pivot tolerance: 0.001
Only used if diagonal pivoting is attempted.
16: scaling: 1 (divide each row by sum of abs. values in each row)
17: frontal matrix allocation ratio: 0.5
18: drop tolerance: 0
19: AMD and COLAMD aggressive absorption: 1 (yes)
The following options can only be changed at compile-time:
8: BLAS library used: Fortran BLAS. size of BLAS integer: 8
9: compiled for MATLAB
10: CPU timer is POSIX times ( ) routine.
11: compiled for normal operation (debugging disabled)
computer/operating system: Linux
size of int: 4 UF_long: 8 Int: 8 pointer: 8 double: 8 Entry: 8 (in bytes)
sp\: UMFPACK's factorization was successful.
sp\: UMFPACK's solve was successful.
UMFPACK V5.4.0 (May 20, 2009), Info:
matrix entry defined as: double
Int (generic integer) defined as: UF_long
BLAS library used: Fortran BLAS. size of BLAS integer: 8
MATLAB: yes.
CPU timer: POSIX times ( ) routine.
number of rows in matrix A: 10
number of columns in matrix A: 10
entries in matrix A: 26
memory usage reported in: 16-byte Units
size of int: 4 bytes
size of UF_long: 8 bytes
size of pointer: 8 bytes
size of numerical entry: 8 bytes
strategy used: unsymmetric
ordering used: colamd on A
modify Q during factorization: yes
prefer diagonal pivoting: no
pivots with zero Markowitz cost: 2
submatrix S after removing zero-cost pivots:
number of "dense" rows: 0
number of "dense" columns: 0
number of empty rows: 0
number of empty columns 0
submatrix S not square or diagonal not preserved
symbolic factorization defragmentations: 0
symbolic memory usage (Units): 238
symbolic memory usage (MBytes): 0.0
Symbolic size (Units): 57
Symbolic size (MBytes): 0
symbolic factorization CPU time (sec): 0.00
symbolic factorization wallclock time(sec): 0.00
matrix scaled: yes (divided each row by sum of abs values in each row)
minimum sum (abs (rows of A)): 1.21495e-01
maximum sum (abs (rows of A)): 2.36586e+00
symbolic/numeric factorization: upper bound actual %
variable-sized part of Numeric object:
initial size (Units) 171 161 94%
peak size (Units) 938 899 96%
final size (Units) 39 28 72%
Numeric final size (Units) 130 114 88%
Numeric final size (MBytes) 0.0 0.0 88%
peak memory usage (Units) 1189 1150 97%
peak memory usage (MBytes) 0.0 0.0 97%
numeric factorization flops 1.79000e+02 3.30000e+01 18%
nz in L (incl diagonal) 31 19 61%
nz in U (incl diagonal) 36 23 64%
nz in L+U (incl diagonal) 57 32 56%
largest front (# entries) 42 6 14%
largest # rows in front 7 3 43%
largest # columns in front 6 3 50%
initial allocation ratio used: 0.7
# of forced updates due to frontal growth: 0
nz in L (incl diagonal), if none dropped 19
nz in U (incl diagonal), if none dropped 23
number of small entries dropped 0
nonzeros on diagonal of U: 10
min abs. value on diagonal of U: 1.30e-01
max abs. value on diagonal of U: 9.70e-01
estimate of reciprocal of condition number: 1.35e-01
indices in compressed pattern: 12
numerical values stored in Numeric object: 29
numeric factorization defragmentations: 1
numeric factorization reallocations: 1
costly numeric factorization reallocations: 1
numeric factorization CPU time (sec): 0.16
numeric factorization wallclock time (sec): 0.17
numeric factorization mflops (CPU time): 0.00
numeric factorization mflops (wallclock): 0.00
solve flops: 2.58000e+02
iterative refinement steps taken: 0
iterative refinement steps attempted: 0
sparse backward error omega1: 2.11e-16
sparse backward error omega2: 0.00e+00
solve CPU time (sec): 0.00
solve wall clock time (sec): 0.00
total symbolic + numeric + solve flops: 2.91000e+02
ans =
-8.8364
29.2610
72.4619
51.8905
-42.4795
-46.4504
0.5000
5.6994
12.7503
45.2984