Question

In: Computer Science

: Find the inverse of the three matrices listed below. The code should prompt the user...

: Find the inverse of the three matrices listed below. The code should prompt the user to input the size of the matrix and to put the value of each element in the matrix. The output should contain the solution to the inverse from using a function created by you, and the solution found using the NumPy package.

I1 = [ 1 2 3 4]−1

I2 = [ 1 2 3 4 5 6 7 2 9 ] −1

I3 =[ 1 3 5 9 1 3 1 7 4 3 9 7 5 2 0 9 ] −1

Solutions

Expert Solution


"""
  Python program for inverse of matrix
"""

import numpy as np

def getInverse(matrix):
  try:
    inverse = np.linalg.inv(matrix)
  except np.linalg.LinAlgError:
    print('Inverse does not exist')
    pass
  else:
    print('Inverse of matrix -')
    print(inverse)

def main():
  R,C = map(int, input("Enter size of matrix: ").split())

  print("Enter matrix({},{}): ".format(R,C), end='')

  entries = list(map(int, input().split()))

  matrix = np.array(entries).reshape(R, C)
  print(matrix)

  getInverse(matrix)

if __name__ == '__main__':
  main()

# Program ends here


Related Solutions

This code needs to be in C++, please. Step 1: Add code to prompt the user...
This code needs to be in C++, please. Step 1: Add code to prompt the user to enter the name of the room that they are entering information for. Validate the input of the name of the room so that an error is shown if the user does not enter a name for the room. The user must be given an unlimited amount of attempts to enter a name for the room. Step 2: Add Input Validation to the code...
Reuse the code to prompt the user for a specific day, test whether it is within...
Reuse the code to prompt the user for a specific day, test whether it is within range, and then output the estimated concrete strength from the fitted curve using polyval. Run your function from the command window for 2 different days to test the functioning of your code. The program should preferably loop until the user asks to exit. where x = days y = rain (mm) x = [0 1 2 3 7 14 28]; y = [0 4...
I need a java code Write a simple program to prompt the user for a number...
I need a java code Write a simple program to prompt the user for a number between 1 and 12 (inclusive) and print out the corresponding month. For example:   The 12th month is December. Use a java "switch" statement to convert from the number (1-12) to the month. Also use a "do while" loop and conditional checking to validate that the number entered is between 1 and 12 inclusive and if not, prompt the user again until getting the correct...
C code please (1) Prompt the user to enter a string of their choosing. Store the...
C code please (1) Prompt the user to enter a string of their choosing. Store the text in a string. Output the string. (1 pt) Ex: Enter a sample text: we'll continue our quest in space. there will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. nothing ends here; our hopes and our journeys continue! You entered: we'll continue our quest in space. there will be more shuttle flights and...
Write a java code snippet to prompt the user for the number of names they’d like...
Write a java code snippet to prompt the user for the number of names they’d like to enter. Create a new array of the size chosen by the user and prompt the user for each of the names. Output the list of names in reverse order.
Program should be written in Java b) The computer program should prompt the user (You are...
Program should be written in Java b) The computer program should prompt the user (You are the user) to enter the answers to the following questions: What is your city of birth? What is your favorite sport? If you could live anywhere in the world, where would you like to live? What is your dream vacation? Take this information and create a short paragraph about the user and output this paragraph. You may use the Scanner class and the System.out...
Write the complete code necessary to prompt the user for 4 sequential numbers, calculate the summation...
Write the complete code necessary to prompt the user for 4 sequential numbers, calculate the summation of the 4 numbers and display the results including the words "The summation of 1,2,3,4 is". A summation is defined as n + n+1 + n+2.... Declare necessary variables and be sure to include comments. Include int main(void) { Code goes here } The programming language is C in Visual Basic
Explain why three aspects (that are listed below)from the Code of Ethical Principles and Standards of...
Explain why three aspects (that are listed below)from the Code of Ethical Principles and Standards of Professional Practice are important to your NPO? Practice their profession with integrity, honesty, truthfulness, and adherence to the absolute obligation to safeguard the public trust. Act according to the highest goals and visions of their organizations, professions, clients, and consciences. Put philanthropic mission above personal gain.
Pythpn #Exercise 1 #Ask the user for a three letter word using the prompt: three letter...
Pythpn #Exercise 1 #Ask the user for a three letter word using the prompt: three letter word? (include a space after the ?) #Display the entire word #Display the word vertically, one letter at a time using print statements and the string index #For example, if the user enters baa, the output should be (ignore # signs): #baa #b #a #a #Exercise 2 #Ask the user for a number using the prompt: first number? (include a space after the ?)...
Description: The search method should prompt the user for a search phrase. Given the search phrase...
Description: The search method should prompt the user for a search phrase. Given the search phrase the search method should search each line in the file for the location of the phrase on each line. If the search phrase is not found on a line then just go to the next line. The search method must find every occurrence of the phrase on a line. The search method should print the line number, the line and the location of the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT