user3263843
user3263843

Reputation: 21

Matrix using matlab

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.

Upvotes: 2

Views: 861

Answers (2)

Matt J
Matt J

Reputation: 1137

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.

Upvotes: 0

NKN
NKN

Reputation: 6434

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).

Upvotes: 1

Related Questions