Question

In: Computer Science

Write the following Python script: Write a function called linsolve() that will be useful in categorizing...

Write the following Python script:

Write a function called linsolve() that will be useful in categorizing and solving linear algebra problems. The function will have up to three parameters:

• A required 2D array representing the coefficient matrix of a linear algebra equation,

• A required 1D or 2D array representing the right-side constants of a linear algebra equations, and

• An optional parameter used to determine which condition number to use in determining the condition of the system. The default case for this is the integer 2.

The returns for this function will depend on whether there is a unique solution to the system. If there is, the three returns should be, in order:

• A 1D or 2D array representing the solution array of the linear system,

• A float representing the determinant of the coefficient matrix, and

• A float representing the condition number of the coefficient matrix.

If there is no unique solution, the function should return None for the solution array, 0 for the determinant, and -1 for the condition number; the function should also print out “No solution.”

Solutions

Expert Solution

These task could be solved using numpy :

Here is a code snippet in Python for above task attached with screenshot of output

import numpy as np
def linsolve(A,B,condition):
    a=np.array(A)#matrix A into array
    b=np.array(B)#matrix B into array
    det=np.linalg.det(A)#det for storing determinant
    if det==0:
        print("Infinite Solution")
        return "None",0,-1
    else:
        x=np.linalg.solve(a,b)
        return x,det,1
m_list=[[6,1,1],[2,2,2],[2,8,7]]
x,determinant,cond=linsolve(m_list,[1,2,3],2)
print(x)
print(determinant)
print(cond)

OUTPUT'S SCREENSHOT

1.

2.


Related Solutions

Using Python create a script called create_notes_drs.py. In the file, define and call a function called...
Using Python create a script called create_notes_drs.py. In the file, define and call a function called main that does the following: Creates a directory called CyberSecurity-Notes in the current working directory Within the CyberSecurity-Notes directory, creates 24 sub-directories (sub-folders), called Week 1, Week 2, Week 3, and so on until up through Week 24 Within each week directory, create 3 sub-directories, called Day 1, Day 2, and Day 3 Bonus Challenge: Add a conditional statement to abort the script if...
Write a script or function in Python that approximates the solution to the system ??⃗=?⃗⃗ using...
Write a script or function in Python that approximates the solution to the system ??⃗=?⃗⃗ using the Jacobi Method. The inputs should be an nxn matrix A, an n-dimensional vector?⃗⃗, a starting vector ?⃗0,an error tolerance ?, and a maximum number of iterations N. The outputs should be either an approximate solution to the system??⃗=?⃗⃗ or an error message, along with the number of iterations completed. Additionally, it would be wise to build in functionality that allows you to optionally...
In python please write the following code the problem. Write a function called play_round that simulates...
In python please write the following code the problem. Write a function called play_round that simulates two people drawing cards and comparing their values. High card wins. In the case of a tie, draw more cards. Repeat until someone wins the round. The function has two parameters: the name of player 1 and the name of player 2. It returns a string with format '<winning player name> wins!'. For instance, if the winning player is named Rocket, return 'Rocket wins!'.
#Python 5. Write function called evaluate() that evaluates the following Python expressions or assignments as specified:...
#Python 5. Write function called evaluate() that evaluates the following Python expressions or assignments as specified: Request input from the user for three variables (floating-point or integer) x, y, z, and myAverage. If the average of the first three numbers equals the fourth number, print 'Your average is correct.'. If not print 'Your average is not correct'. and print the correct average. Print the largest value among x, y, and z. Print the minimum value of x, y, y. >>>...
Python Create a Python script file called hw3.py. Ex. 1. Write a program that inputs numbers...
Python Create a Python script file called hw3.py. Ex. 1. Write a program that inputs numbers from the user until they enter a 0 and computes the product of all these numbers and outputs it. Hint: use the example from the slides where we compute the sum of a list of numbers, but initialize the variable holding the product to 1 instead of 0. print("Enter n") n = int(input()) min = n while n != 0: if n < min:...
This is python: #Write a function called count_positive_evens. This function #should take as input a list...
This is python: #Write a function called count_positive_evens. This function #should take as input a list of integers, and return as #output a single integer. The number the function returns #should be the count of numbers from the list that were both #positive and even. # #For example: # # count_positive_evens([5, 7, 9, 8, -1, -2, -3]) -> 1 # count_positive_evens([2, 4, 6, 8, 10, 12, 15]) -> 6 # count_positive_evens([-2, -4, -6, -8, -10, 1]) -> 0 # #0...
Write a python function called HackCaesar with the following requirements: def hack_caesar(cyphertext): ‘’’ cyphertext is a...
Write a python function called HackCaesar with the following requirements: def hack_caesar(cyphertext): ‘’’ cyphertext is a text encoded using Caesars encryption. The encryption key is unknown. The function returns the correct encryption key. Hint: Use the function we wrote was called caesar(c, key) and could encode a single character. # YOUR CODE GOES HERE def is_odd(n): return n%2 == 1 def caesar(c, key): """ Encrypts a lower case character c using key Example: if c = "a" and key=3 then...
Write the following Python script: Imagine you live in a world without modules in Python! No...
Write the following Python script: Imagine you live in a world without modules in Python! No numpy! No scipy! Write a Python script that defines a function called mat_mult() that takes two lists of lists as parameters and, when possible, returns a list of lists representing the matrix product of the two inputs. Your function should make sure the lists are of the appropriate size first - if not, your program should print “Invalid sizes” and return None. Note: it...
Write the following Python script: Imagine you live in a world without modules in Python! No...
Write the following Python script: Imagine you live in a world without modules in Python! No numpy! No scipy! Write a Python script that defines a function called mat_mult() that takes two lists of lists as parameters and, when possible, returns a list of lists representing the matrix product of the two inputs. Your function should make sure the lists are of the appropriate size first - if not, your program should print “Invalid sizes” and return None. Note: it...
Write the following Python script: Imagine you live in a world without modules in Python! No...
Write the following Python script: Imagine you live in a world without modules in Python! No numpy! No scipy! Write a Python script that defines a function called mat_mult() that takes two lists of lists as parameters and, when possible, returns a list of lists representing the matrix product of the two inputs. Your function should make sure the lists are of the appropriate size first - if not, your program should print “Invalid sizes” and return None. Note: it...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT