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...
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.
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
C++ Code Writing prompt: Grade Calculation: Write a program that asks the user to enter in...
C++ Code Writing prompt: Grade Calculation: Write a program that asks the user to enter in a number greater than or equal to zero and less than or equal to 100. If they do not you should alert them and end the program. Next, determine the letter grade associated with the number. For example, A is any grade between 90 and 100. Report the letter grade to the user.
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.
create a program that will verify a user's login credentials. The program should prompt the user...
create a program that will verify a user's login credentials. The program should prompt the user to enter his/her username and password at the keyboard. Then it should read the data from a data file named "login.txt". The file "login.txt" will contain a list of 3 valid usernames and passwords to verify the login information supplied by a user.  If the username and password entered by the user matches one of the sets read from the file, the program should print...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT