You are on page 1of 2

Assignment 1.

Use format short.


Make up a 5-by-5 matrix A, with 0.0001 in the (1,1) position. Type
>> help det
and scan the instructions. Note that in the "help" statements, MATLAB uses capit
al letters (DET), but you are supposed to use the lower-case version.
Get the determinant of your matrix A.
>> m = det(A)
If your matrix is singular, change it.
Now type
>> help lu
and briefly look over the instructions. Get the LU factorization of A.
[L1,U1]=lu(A) .
Note that the L1 matrix is not truly a lower triangular matrix, because pivoting
was performed. Multiply L1 times U1, and you will see A.
Now perform
[L2,P,U2] = lu(A) .
This time you will get a truly lower triangular L2 and upper triangular U2, but
L2*U2 will not equal A. Verify this.
The permutation matrix P tells you which row switches were made, during the LU f
actorization, to accomodate pivoting. In other words, L2*U2 gives you P*A, which
is A with its rows
switched. Verify this. As further verification, perform LU on P*A, and verify t
hat you get L2 and U2.
Finally, verify that the same row switches, performed on L1, gives you L2.
Hand in the MATLAB script for these steps:
[L1,U1]=lu(A)

% (L1 will NOT be lower triangular)

Acheck1 = L1*U1
Acheck1- A

% (L1*U1 equals A)

[L2,U2,P] = lu(A) % (L2 IS lower triangular)


Acheck2 = L2*U2
Acheck2-A

% (But L2*U2 is Not equal to A)

Aswitched = P*A % (Switch the rows of A)

L2*U2 - P*A

% ( L2*U2 gives you A with its rows switched)

[L3,U3] = lu(Aswitched) % (Now L3 IS lower triangular)


L3 - L2

% (and L3 = L2)

L1switched = P*L1

% (Perform the same rwo-switching on L1)

L2 - L1switched

& (and observe that L2 is the same as L1 switched)

My point is this. When you start to do LU factorization on a matrix, you don't k


now - at the outset - which row permutations are going to be called for (due to
pivoting). But if somehow you DID know which rows were going to be permuted, and
if you permuted them yourself at the outset, then then LU factorization would p
roceed without pivoting.
Copy and paste the above commands and the results in "online submission" box in
Canvas.

You might also like