You are on page 1of 17

Matlab Final Project

Brandon Simon
CSC 215
Professor Edward Kim
Due 2014-05-09
To Be Discussed
Purpose
Determinant: Background
Determinant: findpiv Purpose
Determinant: findpiv code
Determinant: slu Purpose
Determinant: slu code
Determinant Elaboration
Determinant code
Inverse Elaboration
Inverse code
Gauss Jordan Elimination
Elaboration
Gauss Jordan Elimination code
Purpose
The main objective of this project is to demonstrate proficiency
in matlab as well as to show a general understanding of coding.
There was a total of three functions created
The primary matlab function that was created can be used to find the
determinant of any nxn matrix.
The secondary matlab function can find the inverse of any nxn matrix.
The tertiary matlab function can do gauss Jordan elimination of any nxn
matrix to find the values of any three arbitrary constants
Other functions used were supplied by MIT
Determinant: Background
The determinant utilized lu decomposition.
The premise of this system is that A = LUP
-1
, where L and U are
lower and upper triangular matrices, respectively, and P is the
permutation matrix.
A when factored has a matrix L, which has a diagonal of 1s.
This approach allowed us to simplify the code used as finding the
determinant of triangular matrices is the product of the diagonal.
Problems were then found when finding the sign of the det(A).
The sign is usually found by finding the determinant of the inverse
permutation matrix, but this process can simplified.
Determinant: Background
The det(P
-1
) can be simplified to (-1)
s
where s is the number of
row exchanges used to find L and U.
Problems were immediately found when using this simplification
process as this is not completely accurate as certain rows may
be completed using only one row exchange.
This problem had many possible approaches
Keeping track of the ratio of the rows and adjusting the count
accordingly.
Finding the determinant of the matrix, however redundant it maybe
Designing or finding a code to do the lu decomposition of the code as
well as to keep a count of the how many times the process runs.
Determinant: Background
The easiest solution was finding code, which is supplied by MIT
as it is well beyond the scope of our class.
The code had slight alterations, as it provided more information
than necessary.
The code has a nested partial pivot function with in it, that will
be discussed in detail in the next slide.
Determinant: findpiv Purpose
This code does a partial pivot
This means the matrix is adjusted for future use in row
reduction and decomposition
This is code takes the input A, the matrix to be pivoted, and
outputs the [r, p], such that A(r, p) is the pivot of A at a specific
value.

Determinant: findpiv code
Determinant: slu purpose
slu is lu decomposition with the outputs being the sign, the
upper triangular matrix, and the lower triangular matrix.
This program goes through the process of factoring the matrix A
into the upper triangular matrix, U, and lower triangular matrix,
L.
The program also keeps track of the sign. This is done by
initializing the sign to (-1)
0
which is equal to 1, and then setting
the itself equal to the negative of itself every run through of a
row reduction.
Determinant: slu code
Determinant Elaboration
The program takes any size matrix as an input and produces
the determinant as an output.
The code begins with the custom lu decomposition code,
factoring A into U and L, and gives the determinant of the
inverse of the permutation matrix..
X is made a symbolic variable and then set to 1.
A is then sized with the rows and columns set to m and n.
The if statement is then started if the matrix is square(m == n).
Otherwise, an error is shown.
Determinant Elaboration
If the matrix is square then the determinant is calculated.
To find this we take our output, X, and set it equal to itself times
a value of the diagonal of U, and is repeated until the entire
diagonal is multiplied.
The magnitude is then multiplied by the correcting sign.
The function digits is used to correct the determinant for when it
is equal to 0.

Determinant Code
Inverse Elaboration
The inverse is calculated by taking the adjugate of the matrix
and dividing the whole by the determinant.
The adjugate is found by doing the transpose of the matrix of
cofactors.
Problems were also found in regard to signs when the
determinants sign was off.
Inverse Code
Non square matrices cannot have an
inverse
Sets the adjugate matrix at (i,j) to the
determinant of the matrix not in row or
column (i,j)
Sets the inverse equal to adjugate
matrix divided by the determinate.
Gauss Jordan Elimination Elaboration
This function solves systems of linear equations.
This is done using lu decomposition and then using forward and
backwards substitution.

=
LU = A
=
UX = Y
=
Y = B/L
= /
X = B/LU
=
UX = B/L
= /
LU = A
= /
Gauss Jordan Code

You might also like