Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using Python, write a program that will use matrix reduction to calculate the inverse of a matrix. The code MUST follow the following structure inp

Using Python, write a program that will use matrix reduction to calculate the inverse of a matrix.

The code MUST follow the following structure

inp = input() #reads in the matrix inp_strip = inp.strip("(),[] ") #removes brackets or parantheses and spaces matrix = [list(map(float, t.split(","))) for t in inp_strip.split(";")] #creates a matrix for input

def make_extended_matrix(mat): R = len(mat) # number of rows C = len(mat[0]) # number of columns '''Your Code Goes Here''' #we need to go to each row and then through each column. If we are on the diagonal, we add a 1.0 to the row. Otherwise we add a 0.0 '''Your Code Goes Here''' '''Your Code Goes Here''' mat[m] = mat[m]+[1.0] '''Your Code Goes Here''' '''Your Code Goes Here''' #extends the matrix with an identity matrix on the right return mat

'''Your Code Goes Here''' #You need to insert the code for the reduced echelon calculator, but you need to modify it to define the length of the inputs locally. # For instance, mult_row_by_num(row,a) can use len(row) to determine the value used in the for loop range

def inverse_calculator(mat): C = len(mat[0]) R = len(mat) '''Your Code Goes Here''' #this is the case where the matrix is not square else: '''Your Code Goes Here''' #use make_extended_matrix to create the augmented matrix reduced_extended_matrix = reduced_echelon_calculator(mat) #do the matrix reduction to produce a reduced row echelon on one side and the potential inverse of the other '''Your Code Goes Here''' #This is the case where the matrix is square but not invertible. Hint: If the last column of the left side matrix does not have a one (it would be zero) at the bottom, there is a free variable and the matrix is not invertible '''Your Code Goes Here''' #Otherwise we continue inverse = [[0 for _ in range(C)] for _ in range(R)] # creates matrix of the correct size '''Your Code Goes Here''' '''Your Code Goes Here''' #we need a double for loop to run through right side of the augmented matrix inverse[i][j-C] = reduced_extended_matrix[i][j] return inverse

simplified = inverse_calculator(matrix)

if type(simplified) == str: print(simplified) else: for r in simpified: print(r) #THANKS in advance!

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

Oracle 10g SQL

Authors: Joan Casteel, Lannes Morris Murphy

1st Edition

141883629X, 9781418836290

More Books

Students also viewed these Databases questions

Question

What do you enjoy/not enjoy?

Answered: 1 week ago