b=[2;4;6]
b =
2
4
6
A=[1,2,3;4,5,6;7,8,9]
A =
1 2 3
4 5 6
7 8 9
Ainv=inv(A)
[Warning: Matrix is close to singular or badly scaled. Results may be inaccurate.
RCOND = 1.541976e-18.]
Ainv =
1.0e+16 *
-0.4504 0.9007 -0.4504
0.9007 -1.8014 0.9007
-0.4504 0.9007 -0.4504
Ainv*b
ans =
-4
8
0
A=[1,2,3;4,5,6;7,8,10]
A =
1 2 3
4 5 6
7 8 10
Ainv=inv(A)
Ainv =
-0.6667 -1.3333 1.0000
-0.6667 3.6667 -2.0000
1.0000 -2.0000 1.0000
x_direct_inv=Ainv*b
x_direct_inv =
-0.6667
1.3333
-0.0000
x_direct_LU=A\b
x_direct_LU =
-0.6667
1.3333
0.0000
x_direct_inv-x_direct_LU
ans =
1.0e-14 *
0.0666
-0.1110
-0.0952
help eps
eps Spacing of floating point numbers.
D = eps(X), is the positive distance from ABS(X) to the next larger in
magnitude floating point number of the same precision as X.
X may be either double precision or single precision.
For all X, eps(X) is equal to eps(ABS(X)).
eps, with no arguments, is the distance from 1.0 to the next larger double
precision number, that is eps with no arguments returns 2^(-52).
eps('double') is the same as eps, or eps(1.0).
eps('single') is the same as eps(single(1.0)), or single(2^-23).
Except for numbers whose absolute value is smaller than REALMIN,
if 2^E <= ABS(X) < 2^(E+1), then
eps(X) returns 2^(E-23) if ISA(X,'single')
eps(X) returns 2^(E-52) if ISA(X,'double')
For all X of class double such that ABS(X) <= REALMIN, eps(X)
returns 2^(-1074). Similarly, for all X of class single such that
ABS(X) <= REALMIN('single'), eps(X) returns 2^(-149).
Replace expressions of the form
if Y < eps * ABS(X)
with
if Y < eps(X)
Example return values from calling eps with various inputs are
presented in the table below:
Expression Return Value
===========================================
eps(1/2) 2^(-53)
eps(1) 2^(-52)
eps(2) 2^(-51)
eps(realmax) 2^971
eps(0) 2^(-1074)
eps(realmin/2) 2^(-1074)
eps(realmin/16) 2^(-1074)
eps(Inf) NaN
eps(NaN) NaN
-------------------------------------------
eps(single(1/2)) 2^(-24)
eps(single(1)) 2^(-23)
eps(single(2)) 2^(-22)
eps(realmax('single')) 2^104
eps(single(0)) 2^(-149)
eps(realmin('single')/2) 2^(-149)
eps(realmin('single')/16) 2^(-149)
eps(single(Inf)) single(NaN)
eps(single(NaN)) single(NaN)
See also realmax, realmin.
Other functions named eps
Reference page in Help browser
doc eps
eps
ans =
2.2204e-16
help lu
lu lu factorization.
[L,U] = lu(A) stores an upper triangular matrix in U and a
"psychologically lower triangular matrix" (i.e. a product of lower
triangular and permutation matrices) in L, so that A = L*U. A can be
rectangular.
[L,U,P] = lu(A) returns unit lower triangular matrix L, upper
triangular matrix U, and permutation matrix P so that P*A = L*U.
[L,U,p] = lu(A,'vector') returns the permutation information as a
vector instead of a matrix. That is, p is a row vector such that
A(p,:) = L*U. Similarly, [L,U,P] = lu(A,'matrix') returns a
permutation matrix P. This is the default behavior.
Y = lu(A) returns the output from LAPACK'S DGETRF or ZGETRF routine if
A is full. If A is sparse, Y contains the strict lower triangle of L
embedded in the same matrix as the upper triangle of U. In both full
and sparse cases, the permutation information is lost.
[L,U,P,Q] = lu(A) returns unit lower triangular matrix L, upper
triangular matrix U, a permutation matrix P and a column reordering
matrix Q so that P*A*Q = L*U for sparse non-empty A. This uses UMFPACK
and is significantly more time and memory efficient than the other
syntaxes, even when used with COLAMD.
[L,U,p,q] = lu(A,'vector') returns two row vectors p and q so that
A(p,q) = L*U. Using 'matrix' in place of 'vector' returns permutation
matrices.
[L,U,P,Q,R] = lu(A) returns unit lower triangular matrix L, upper
triangular matrix U, permutation matrices P and Q, and a diagonal
scaling matrix R so that P*(R\A)*Q = L*U for sparse non-empty A.
This uses UMFPACK as well. Typically, but not always, the row-scaling
leads to a sparser and more stable factorization. Note that this
factorization is the same as that used by sparse MLDIVIDE when
UMFPACK is used.
[L,U,p,q,R] = lu(A,'vector') returns the permutation information in two
row vectors p and q such that R(:,p)\A(:,q) = L*U. Using 'matrix'
in place of 'vector' returns permutation matrices.
[L,U,P] = lu(A,THRESH) controls pivoting in sparse matrices, where
THRESH is a pivot threshold in [0,1]. Pivoting occurs when the
diagonal entry in a column has magnitude less than THRESH times the
magnitude of any sub-diagonal entry in that column. THRESH = 0 forces
diagonal pivoting. THRESH = 1 is the default.
[L,U,P,Q,R] = lu(A,THRESH) controls pivoting in UMFPACK. THRESH is a
one or two element vector which defaults to [0.1 0.001]. If UMFPACK
selects its unsymmetric pivoting strategy, THRESH(2) is not used. It
uses its symmetric pivoting strategy if A is square with a mostly
symmetric nonzero structure and a mostly nonzero diagonal. For its
unsymmetric strategy, the sparsest row i which satisfies the criterion
A(i,j) >= THRESH(1) * max(abs(A(j:m,j))) is selected. A value of 1.0
results in conventional partial pivoting. Entries in L have absolute
value of 1/THRESH(1) or less. For its symmetric strategy, the diagonal
is selected using the same test but with THRESH(2) instead. If the
diagonal entry fails this test, a pivot entry below the diagonal is
selected, using THRESH(1). In this case, L has entries with absolute
value 1/min(THRESH) or less. Smaller values of THRESH(1) and THRESH(2)
tend to lead to sparser lu factors, but the solution can become
inaccurate. Larger values can lead to a more accurate solution (but
not always), and usually an increase in the total work and memory
usage.
[L,U,p] = lu(A,THRESH,'vector') and [L,U,p,q,R] = lu(A,THRESH,'vector')
are also valid for sparse matrices and return permutation vectors.
Using 'matrix' in place of 'vector' returns permutation matrices.
See also chol, ilu, qr.
Other functions named lu
Reference page in Help browser
doc lu
diary off