2
votes

this is my first question on this website. I'm looking at a Matlab problem, and don't seem to know how to do it. Before I type the question, I want to make it clear that I'm looking for an UNDERSTANDING, NOT an ANSWER. Although, I must admit, I won't be angry if an answer is posted. But more importantly, I need to understand this.

"The matrix factorization LU = PA can be used to compute the determinant of A. We have

det(L)det(U) = det(P)det(A).

Because L is triangular with ones on the diagonal, det(L) = 1. Because U is triangular, det(U) = u 11 u 22 · · · u nn . Because P is a permutation, det(P) = +1 if the number of interchanges is even and −1 if it is odd. So det(A) = ±u 11 u 22 · · · u nn .

Modify the lutx function so that it returns four outputs.

function [L,U,p,sig] = lutx(A)
%LU Triangular factorization
% [L,U,p,sig] = lutx(A) computes a unit lower triangular
% matrix L, an upper triangular matrix U, a permutation
% vector p, and a scalar sig, so that L*U = A(p,:) and
% sig = +1 or -1 if p is an even or odd permutation.

Write a function mydet(A) that uses your modified lutx to compute the determinant of A. In Matlab, the product u 11 u 22 · · · u nn can be computed by the expression prod(diag(U))."`

The lutx code can be found here:

I'm having difficulty understanding the concept of the problem, and also the code that needs to be written. Any help would be very appreciated. Thank you.

2
looks like a homework to me ;) - NKN
It is. Am I in the wrong to post it? It's why I'm asking for pointers versus an answer. - user3263843
If you expect someone solve it for you, yes. You need to show what have you tried so far, and people can help you to solve the problems you are dealing with. - NKN
That's understandable. Unfortunately, this is a difficult class for me, and I wish that I could say that I've tried a lot. Truth is, I'm struggling with an overall understanding of how a matrix A is decomposed into an upper, lower, and permutation (even though I am perfectly aware of what they are). After typing the lutx code into octave, it produces one matrix, and I don't know what it is! I expected a lower, upper, and permutation matrix to be in the output. So that's the first problem, and the only one I have right now, because I don't know how to go further than that. - user3263843

2 Answers

1
votes

As you mentioned in your problem in the following equation:

det(L)det(U) = det(P)det(A)

actually the lutx function decompose the input matrix and returns the decomposed elements. It means if you give it the A matrix, it will calculate the L,U,p. you can check the source code.

actually in your problem, three out of four elements are 'known', so you can use the lutx function to find the det(A). because :

det(A) = det(L)det(U) / det(P);

so what you can do is this:

[L,U,p,sig] = lutx(A); % here I am using the modified version of lutx that you mentioned
DetA = 1 * prod(diag(U)) * sig; 

because, det(L) = 1 (I mention it in the previous line of code just for underestanding), and det(U) = prod(diag(U)), and sig gives the sign.

finally you can compare your result with matlab function: det(A).

0
votes

The exercise appears to be mainly to compute "sig", which lutx currently doesn't return. As a hint, you must compute

 delta_p = (1:length(p))-p;

and check whether delta_p has an even or odd number of non-zero elements. That will determine the sign of sig.