generate a random matrix: >>A=rand(4) A = 0.8147 0.6324 0.9575 0.9572 0.9058 0.0975 0.9649 0.4854 0.1270 0.2785 0.1576 0.8003 0.9134 0.5469 0.9706 0.1419 type help lu to see documentation of LU decomposition. Perform an LU decomposition of A: USE THE COMMAND >> [LL,UU,PP] = lu(A) to get LL = 1.0000 0 0 0 0.9917 1.0000 0 0 0.8920 -0.3250 1.0000 0 0.1390 -0.4552 0.2567 1.0000 UU = 0.9134 0.5469 0.9706 0.1419 0 -0.4448 0.0024 0.3447 0 0 0.0925 0.9426 0 0 0 0.6955 As you can see LL and UU have the structure we expect. The matrix PP is called the Permutation Matrix: this performs ROW EXCHANGES. matlab “performed” row exchanges before applying elementary row operations (save for the row exchanges) to get an LU factorization. More details on this? take a numerical linear algebra course. PP = 0 0 0 1 0 1 0 0 1 0 0 0 0 0 1 0 =================================================== the lu command in matlab can be used differently: Take another matrix, A = 0.8147 0.6324 0.9575 0.9572 0.9058 0.0975 0.9649 0.4854 0.1270 0.2785 0.1576 0.8003 0.9134 0.5469 0.9706 0.1419 Perform the decomposition now this way: >> [LL,UU]=lu(A) LL = 0.8920 -0.3250 1.0000 0 0.9917 1.0000 0 0 0.1390 -0.4552 0.2567 1.0000 1.0000 0 0 0 UU = 0.9134 0.5469 0.9706 0.1419 0 -0.4448 0.0024 0.3447 0 0 0.0925 0.9426 0 0 0 0.6955 note: see help on LU to understand why LL looks "strange" Check that A=LL*UU >>LL*UU ans = 0.8147 0.6324 0.9575 0.9572 0.9058 0.0975 0.9649 0.4854 0.1270 0.2785 0.1576 0.8003 0.9134 0.5469 0.9706 0.1419 So if you want L to be explicit, use [LL,UU,PP] = lu(A), rather than [LL,UU] = lu(A) ======================================= One way to invert a matrix (but not the recommended way) is by >>inv(A) ans = -15.2997 3.0761 14.7235 9.6445 -0.2088 -1.8442 1.0366 1.8711 14.5694 -1.9337 -14.6497 -9.0413 -0.3690 0.5345 1.4378 -0.4008 The more general way is that Ainverse = A\I, where I is the identity matrix of the same size as A. Generate an identity matrix of size 4X4: >>B = eye(4); Perform the inversion: >>Ainv=A\B Ainv = -15.2997 3.0761 14.7235 9.6445 -0.2088 -1.8442 1.0366 1.8711 14.5694 -1.9337 -14.6497 -9.0413 -0.3690 0.5345 1.4378 -0.4008 ====================================== Computing determinants via matlab is a bad idea...it is very unstable numerically. Take a numerical analysis class to learn more. But for small balanced matrices it's ok. Generate a special matrix called a Hilbert matrix (type help hilb) >>A=hilb(4) A = 1.0000 0.5000 0.3333 0.2500 0.5000 0.3333 0.2500 0.2000 0.3333 0.2500 0.2000 0.1667 0.2500 0.2000 0.1667 0.1429 compute the determinant: >>det(A) ans = 1.6534e-07 =================================== Generate another matrix >>AA=hilb(3) AA = 1.0000 0.5000 0.3333 0.5000 0.3333 0.2500 0.3333 0.2500 0.2000 compute the rank of AA: >> rank(AA) ans = 3 compute the null space of AA >>null(AA) ans = Empty matrix: 3-by-0 Make a copy of AA call it C: >>C=AA replace the 3rd row of C by zeros: >>C(3,:)=zeros(1,3) C = 1.0000 0.5000 0.3333 0.5000 0.3333 0.2500 0 0 0 compute rank of C >>rank(C) ans= 2 compute null space of C: >>null(C) ans = 0.1170 -0.7022 0.7022 compute the det of C det(C) ans = 0 ============================== >> A = hilb(4) Compute eigenvalues and eigenvectors of matrix: >>[VV,DD]=eig(A) VV = -0.6621 -0.7149 0.1745 0.1821 -0.4819 -0.0292 -0.6291 -0.9288 -0.2766 0.6972 0.5995 0.3178 -0.5029 -0.0438 -0.4630 0.0570 DD = 2.4021 0 0 0 0 -0.0346 0 0 0 0 -0.7158 0 0 0 0 -0.4400 Compute eigenvalues/vectors of A transpose = A' >>[VVp,DDp]=eig(A') VVp = -0.5308 -0.6543 -0.3872 -0.0825 -0.3371 0.1107 -0.1442 -0.6424 -0.5902 0.6246 -0.3503 -0.0637 -0.5062 0.4117 0.8406 0.7593 DDp = 2.4021 0 0 0 0 -0.0346 0 0 0 0 -0.7158 0 0 0 0 -0.4400 >>rank(A) ans = ans = 4 >>rank(A') ans = 4