Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

*PLEASE TRANSLATE TO MATLAB CODE * I'LL THUMBS UP IF IT WORKED # Pyhton 3 program for the above approach # Function to find the

*PLEASE TRANSLATE TO MATLAB CODE * I'LL THUMBS UP IF IT WORKED

# Pyhton 3 program for the above approach # Function to find the determinant # of matrix M[][] def determinantOfMatrix(mat, N): mul = 1 # Iterate over N while N > 2 while (N > 2): # Store the reduced matrix # of dimension (N-1)x(N-1) M = [[0 for i in range(N-1)] for j in range(N-1)] next_index = 1 # Check if first element # of first row is zero while (mat[0][0] == 0): if (mat[next_index][0] > 0): # For swapping for k in range(N): temp = mat[0][k] mat[0][k] = mat[next_index][k] mat[next_index][k] = temp # Update mul mul = mul * pow((-1),(next_index)) elif (next_index == (N - 1)): return 0; next_index += 1 # Store the first element # of the matrix p = mat[0][0] # Multiply the mul by # (1/p) to the power n-2 mul = mul * pow(1 / p, N - 2) # Calculate the next matrix # of dimension (N-1) x (N-1) for i in range(1,N): for j in range(1,N,1): # Calculate each element of # the matrix from previous # matrix M[i - 1][j - 1] = mat[0][0] * mat[i][j] - mat[i][0] * mat[0][j] # Copy elements of the matrix # M into mat to use it in # next iteration for i in range(N - 1): for j in range(N - 1): mat[i][j] = M[i][j] # Decrement N by one N -= 1 # Calculate the determinant # of reduced 2x2 matrix and # multiply it with factor mul D = mul * (mat[0][0] * mat[1][1] - mat[0][1] * mat[1][0]) # Print the determinant print(int(D)) # Driver Code if __name__ == '__main__': # Given matrix mat = [[1, 0, 2, -1],[3, 0, 0, 5], [2, 1, 4, -3], [1, 0, 5, 0]] # Size of the matrix N = len(mat) # Function Call determinantOfMatrix(mat, N) # This code is contributed by bgangwar59.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Database Machine Performance Modeling Methodologies And Evaluation Strategies Lncs 257

Authors: Francesca Cesarini ,Silvio Salza

1st Edition

3540179429, 978-3540179429

More Books

Students also viewed these Databases questions

Question

5. Structure your speech to make it easy to listen to

Answered: 1 week ago