Question

In: Computer Science

Write a python function (Without using external libraries) to calculate the 1). determinate of a 2...

Write a python function (Without using external libraries) to calculate the 1). determinate of a 2 x 2 matrix 2). Calculate the inverse of a 2 x 2 matrix.

Solutions

Expert Solution

matrix1=[]
for i in range(0,2):                            # Loops for rows
    element =[]                                 # Creating an empty list for each row
    for j in range(0,2):                        # Loops for columns 
         element.append(int(input()))           # Takes input from user and appends to matrix1
    matrix1.append(element)                     # Appending the scanned element to matrix indexes
Determinant=matrix1[0][0]*matrix1[1][1] - matrix1[0][1]*matrix1[1][0]   # Finding the determinant 
print("Determinant is {}".format(Determinant))            # Prints the determinant

matrix_inv=[[],[]]                              # Creates the empty list of list for rows and columns
store=1/Determinant                             # Stores the inverse of determinant

if(Determinant==0):
    print("Inverse doesnot exist")
else:
    matrix_inv[0].append(matrix1[1][1]*store)   # Does inverse operation for the 1x1 positions
    matrix_inv[0].append(-(matrix1[0][1]*store))# Does inverse operation for the 0x1 positions
    matrix_inv[1].append(-(matrix1[1][0]*store))# Does inverse operation for the 1x0 positions
    matrix_inv[1].append(matrix1[0][0]*store)   # Does inverse operation for the 0x0 positions

print("Inverse of a matrix is {}".format(matrix_inv))   # Prints the inverse of matrix 



Related Solutions

using python without external libaries Using integer arithmetic operators '+' and '-', print all combinations that...
using python without external libaries Using integer arithmetic operators '+' and '-', print all combinations that sum up to 'sum' by inserting the operators between digits in 'number'. example for 'number=123456789' and 'sum = 0' Print the output using the terminal: Output should be exactly like this from 1 - 22 1 : +1+2-34-56+78+9=0 2 : +1-2-34+5+6+7+8+9=0 3 : +1-23-4-56-7+89=0 ... 12 : -1+2+34-5-6-7-8-9=0 13 : -1+23+4+56+7-89=0 14 : -1-2+34+56-78-9=0 ... 22 : -12-34+56+7-8-9=0
For these of string functions, write the code for it in C++ or Python (without using...
For these of string functions, write the code for it in C++ or Python (without using any of thatlanguage's built-in functions) You may assume there is a function to convert Small string into the language string type and a function to convert your language's string type back to Small string type. 1. int [] searchA,ll(string in...str, string sub): returns an array of positions of sub in in...str or an one element array with -1 if sub doesn't exist in in...str
Using Python coding language (with or without Pandas and/or NumPy), 1. Can you define function sleep...
Using Python coding language (with or without Pandas and/or NumPy), 1. Can you define function sleep to tell whether the participant are of the ages through 18 to 60 and sleep less than 6 hours per day? 2. Develop codes to check whether the sleep function you defined can make correct judgement. Make sure you write comments or create informative vairable name so that I can understand how you check the sleep function. (Hints: You can create toy data/dataframe to...
Using Python Question 1 Write an input function. Then use it to supply the input to...
Using Python Question 1 Write an input function. Then use it to supply the input to following additional functions: i) Print multiplication table of the number from 1 to 12. ii) Print the sum of all the numbers from 1 to up the number given. iii) Print if the number supplied is odd or even. Question 2 Write function that asks for input from a user. If the user types 'end', the program exits, otherwise it just keeps going.
Using Python C++ Purpose: Write and test a non-trivial 2-d array function. Write a user-defined function...
Using Python C++ Purpose: Write and test a non-trivial 2-d array function. Write a user-defined function that, given an arbitrary 2-d array as input, returns its perimeter sum, which is defined as the sum of all the elements along its perimeter. You must name your function perimeter_sum
Python - No libraries - No count() function allowed You need to travel 100 miles via...
Python - No libraries - No count() function allowed You need to travel 100 miles via rental car. There are several cars on the lot to choose from, each with their own MPG (miles per gallon) rating. Some cars have a manual transmission, while others do not (they're automatic). The price for gas in the area is $3 per gallon. Cars that have a manual transmission get a 10% discount at the pump. To streamline your selection, the car rental...
Write a program in python that implements quicksort, first using recursion and then without recursion.
Write a program in python that implements quicksort, first using recursion and then without recursion.
Write a Python program which uses a function to calculate the perimeter of a rectangle. a...
Write a Python program which uses a function to calculate the perimeter of a rectangle. a function named volume to calculate the volume of a cylinder volume = 3.14 x radius x radius x height .b function named volume to calculate the volume of a cuboid volume = Length x width x ht Write a Python Program to calculate the sum of all odd numbers for 2 to 20 using a for loop. 4. Write statements that assign random integers...
1) Write a simple python function program that can calculate the volumes of following shape: cylinder,...
1) Write a simple python function program that can calculate the volumes of following shape: cylinder, circle, cone and sphere. For each of this shape, write a separate function. Let your function take in 2 inputs only. Your program should prompt user to enter these 2 inputs and print out the results of the volumes of the shape separately?
using python 1. #Write a function called multiply_file_by_index. This function #should take two parameters, both strings....
using python 1. #Write a function called multiply_file_by_index. This function #should take two parameters, both strings. The first string is #the filename of a file to which to write (output_file), and #the second string is the filename of a file from which to read #(input_file). # #In the input file, there will be an integer on every line. #To the output file, you should write the integer from the #original file multiplied by the line number on which it #appeared....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT