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...
There is error in this java code. Pls debug. // Prompt user for value to start...
There is error in this java code. Pls debug. // Prompt user for value to start // Value must be between 1 and 20 inclusive // At command line, count down to blastoff // With a brief pause between each displayed value import java.util.*; public class DebugSix3 { public static void main(String[] args) { Scanner input = new Scanner(System.in); String userNumString; int userNum, val; final int MIN = 1; final int MAX = 20; System.out.println("Enter a number between " +...
provide a JavaScript code that finds if the given word by user (prompt) is a Palindrome...
provide a JavaScript code that finds if the given word by user (prompt) is a Palindrome or no.
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...
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.
Python: I want to make the following code to prompt the user if want to run...
Python: I want to make the following code to prompt the user if want to run the software again. I am new to python, so i do not know if it works like c++. If can explain that would be much appreciated base = float(input("Enter base of the triagle: ")) Triangle_Right = float(input("Enter right side of the triagle: ")) Triangle_Left = float(input("Enter left side of the triagle: ")) height = float(input("Enter the height of the triangle: ")) perimiter = base...
Write a program that calculates the salary of employees. The program should prompt the user to...
Write a program that calculates the salary of employees. The program should prompt the user to enter hourly rate and number of hours of work a day. Then, the program should display the salary daily, bi-weekly (5 days a week), and monthly. Sample program: Enter your hourly rate: >>> 20 Enter how many hours you work a day: >>> 8 Your daily salary is: $160 Your bi-weekly salary is: $1600 Your monthly: $3200
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT