Matrix Determinants SOlution

$30.00

Description

Given an N N square matrix Ai;j ; 1 i; j N , then the determinant can be defined by the Leibniz formula as

N

det(A) =

sgn( ) Ai; i :

(7.1)

2SN

i=1

where SN is the set of all permutations of f1; 2; ; N g, is one possible permutation in SN , and i is the ith element of the permutation . In Lab 5, the Pandita algorithm has been introduced. Given a permutation (m), the Pandita algorithm generates the next lexicographic permutation

(m+1) with (1) = f1; 2; ; N g. The function sgn( (m)) is defined as the following.

sgn( (m)) = {

1;

if m = 1;

(7.2)

( 1)t sgn( (m 1));

otherwise:

where t is the number of swaps needed for the Pandita algorithm to generate the next permutation. In this assignment, you need to write a C program to calculate the determinant of an N N square matrix using Equations (7.1) and (7.2). Again, the size of the matrix N should be defined

as a macro.

#if !defined(N)

#define N 3

#endif

Twelve matrices with various dimensions have been provided for you to test your program. They are mat1.in, mat2.in, , mat12.in. You should open each file to find the dimension of the matrix and then compile your program with the right dimension as

  • gcc -DN=3 lab07.c

  • ./a.out < mat1.in

The last line uses the unix input redirection method to read input directly from the file mat1.in. In this way, we do not need to retype the matrix every time we execute the program. Example program compilation and execution is shown below.

  • gcc -DN=3 lab07.c

  • ./a.out < mat1.in Input matrix is

1 2 3

4 5 6

7 8 9 Det = 0

Notes.

  1. Create a directory lab07 and use it as the working directory.

  1. Name your program source file as lab07.c.

  1. The first few lines of your program should be comments as the following.

/* EE231002 Lab07. Matrix Determinants ID, Name

Date:

*/

  1. After you finish verifying your program, you can submit your source code by

$ ee231002/bin/submit lab07 lab07.c

If you see a ”submitted successfully” message, then you are done. In case you want to check which file and at what time you submitted your labs, you can type in the following command:

$ ee231002/bin/subrec lab07

It will show the last few submission records.