a1W10 - AMATH 341 / CM 271 / CS 371 Assignment 1 Due :...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
AMATH 341 / CM 271 / CS 371 Assignment 1 Due : Monday January 18, 2010 1. Implement in Matlab two functions function d = det1(A) and function d = det2(A) to compute the determinant of an n × n matrix A using two different algorithms. The first algorithm, det1(A) , applies lutx to A and then computes det( A ) = det( P ) det( L ) det( U ). It is known that det( U ) is the product of its diagonal entries, and this is not hard to implement in Matlab (see prod and diag ). Next, det( L ) is identically 1 so there is nothing to compute. The determinant of P is either 1 or 1. In more detail, it is 1 if P can be factored as an odd number of swaps while it is +1 if P can be factored as an even number of swaps. An algorithm to compute det( P ) from the vector p returned by lutx is as follows. Initialize a counter c to 0. Initialize a loop index j to 1 and then execute the following repeatedly. If p ( j ) = j , then increment j . If p ( j ) ̸ = j , say p ( j ) = i , then swap entries i and j of p , increment c (which counts the number of swaps), and repeat (without incrementing j ). Terminate the loop when j reaches n + 1. (Use a while loop in Matlab.) The function det2 implements the classical recursive formula for a determinant, det( A ) = n j =1 ( 1) 1+ j a 1 j det( A 1 j ) where A ij is the i,j co-factor of A , i.e. the ( n 1) × ( n 1) matrix obtained by removing row i and column j from A . To implement recursion in matlab, first let n be the matrix size (see size ), and take two cases depending on whether n = 1 or n > 1. If n = 1, then det( A ) = A . If
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 06/21/2010 for the course CS 5212 taught by Professor Papoulia,katerina during the Spring '10 term at Waterloo.

Page1 / 5

a1W10 - AMATH 341 / CM 271 / CS 371 Assignment 1 Due :...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online