Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Matlab You will write a function to calculate the determinant of amatrix. It should work for any size matrix. Remember that thedeterminant can be calculated

Matlab

You will write a function to calculate the determinant of amatrix. It should work for any size matrix. Remember that thedeterminant can be calculated by multiplying the diagonal elementsof an upper right triangular matrix. Your function will take amatrix passed to it and put it in upper right triangular form. Youwill work down the diagonal beginning at row 1 column 1, then row 2column 2, etc. Note that the row and column numbers are the same onthe diagonal. You will put zero in each column below the diagonalelements by making linear combinations of rows. Before you makelinear combinations down a column, swap rows (if needed) to put therow with the largest value on the diagonal. Also remember, eachtime you swap rows, the determinant changes sign so count of howmany row swaps are necessary and adjust the sign of the determinantaccordingly. A matrix must be square to have a determinant. If thematrix passed to your function is not square, return the text‘Matrix must be square’.

There are functions included that you MUST use in your function.These will be local functions that follow your main function. Youmust use ALL the functions. The functions are: RowComp(matrix, row,col) which returns the row with the largest absolute value in thecolumn passed to the function beginning at the row passed to thefunction; Swap(matrix, row1, row2) which returns a matrix with row1and row2 exchanged; and LinComb(matrix, row1, row2, alpha) whichreturns a matrix with row2 replaced by row1*alpha+row2. Thesefunctions will make your function much easier to write anddebug.

Your function will be checked with a different matrix of adifferent size. Don’t forget comments and use reasonable variablenames.

Example—if the matrix passed to the function is the determinantis 102.

Interim steps in the calculation:

1. Swap row 3 and row 1

5 2 -2 5

3 4 7 2

1 5 9 3

3 1 7 -3

2. Zeros in column 1

5.0000 2.0000 -2.0000 5.0000

0 2.8000 8.2000 -1.0000

0 4.6000 9.4000 2.0000

0 -0.2000 8.2000 -6.0000

3. Swap row 2 and row 3

5.0000 2.0000 -2.0000 5.0000

0 4.6000 9.4000 2.0000

0 2.8000 8.2000 -1.0000

0 -0.2000 8.2000 -6.0000

4. Zeros in column 2

5.0000 2.0000 -2.0000 5.0000

0 4.6000 9.4000 2.0000

0 0 8.6087 -5.9130

0 0 2.4783 -2.2174

5. Continue until all rows have been completed and zeros are inall columns below the diagonal.

6. Calculate the determinant by multiplying all the diagonalterms together and adjust the sign of the determinant by the numberof row swaps.

Step by Step Solution

3.45 Rating (152 Votes )

There are 3 Steps involved in it

Step: 1

Here is a MATLAB function that calculates the determinant of a square matrix using the method you de... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial Analysis with Microsoft Excel

Authors: Timothy R. Mayes, Todd M. Shank

7th edition

1285432274, 978-1305535596, 1305535596, 978-1285432274

More Books

Students also viewed these Electrical Engineering questions