Question

In: Computer Science

Design a Python class named HomogenEquation for a system of 2x2 linear homogeneous equations: ax+by=e cx+dy=f...

Design a Python class named HomogenEquation for a system of 2x2 linear homogeneous equations:

ax+by=e cx+dy=f

The class should contain:

• The data fields a, b, c, d, e and f.

• A constructor with the arguments a, b, c, d, e and f.

• A method named isSolvable() that returns true if − is not 0.

• The method getXY() that returns the solution for the equation.

Write a test program that prompts the user to enter a, b, c, d, e and f and displays the result. If the equation is not solvable, report that “The equation has no solution.”

Solutions

Expert Solution

The below is the code for the above problem statement:

---------------------------------------------------------------CODE---------------------------------------------------------------------

import numpy as np
class HomogenEquation:
   def __init__(self,a,b,c,d,e,f):
       self.a=a
       self.b=b
       self.c=c
       self.d=d
       self.e=e
       self.f=f
   def isSolvable(self):
       '''
           The linear equation is only solvable
           if (a/b) != (d/e)
           otherwise the equation does not posses an
           unique solution
       '''
       if (self.a/self.b)-(self.d/self.e) != 0:
           return True
       else:
           return False
   def getXY(self):
       '''
           We solve the linear equation with the help of the
           built in function solve() which is defined inside
           numpy.linalg
       '''
       A=np.array([[self.a,self.b],[self.d,self.e]])
       B=np.array([self.c,self.f])
       x,y=np.linalg.solve(A,B)
       return x,y

#Driver Function to Test the functionality of the class
def main():
   a,b,c=map(int,input("Enter Values of a,b,c : ").split())
   d,e,f=map(int,input("Enter Values of d,e,f : ").split())
   Eq=HomogenEquation(a,b,c,d,e,f)
   if Eq.isSolvable():
       x,y=Eq.getXY()
       print("X = ",x,"\nY = ",y)
   else:
       print("The equation has no solution.")
main()

--------------------------------------------------------------------------------END------------------------------------------------------------

Code in sublime text:

OUTPUT:


Related Solutions

Consider the following homogeneous linear system: x1 + 2x2 + 7x3 − 9x4 + 31x5 =...
Consider the following homogeneous linear system: x1 + 2x2 + 7x3 − 9x4 + 31x5 = 0 2x1 + 4x2 + 7x3 − 11x4 + 34x5 = 0 3x1 + 6x2 + 5x3 − 11x4 + 29x5 = 0 [10p] a) Find the rank of the coefficient matrix. [5p] b) Use part (a) to determine the dimension of the solution space. [10p] c) Find a basis for the solution space.
A linear system of equations Ax=b is known, where A is a matrix of m by...
A linear system of equations Ax=b is known, where A is a matrix of m by n size, and the column vectors of A are linearly independent of each other. Please answer the following questions based on this assumption, please explain all questions, thank you~. (1) Please explain why this system has at most one solution. (2) To give an example, Ax=b is no solution. (3) According to the previous question, what kind of inference can be made to the...
Solve the linear system of equations Ax = b, and give the rank of the matrix...
Solve the linear system of equations Ax = b, and give the rank of the matrix A, where A = 1 1 1 -1 0 1 0 2 1 0 1 1 b = 1 2 3
Consider a homogeneous system of linear equations with m equations and n variables. (i) Prove that...
Consider a homogeneous system of linear equations with m equations and n variables. (i) Prove that this system is consistent. (ii) Prove that if m < n then the system has infinitely many solutions. Hint: Use r (the number of pivot columns) of the augmented matrix.
Write a function to solve a system of linear equations of the form Ax= b using...
Write a function to solve a system of linear equations of the form Ax= b using the iterative Gauss-Seidel method. You are free to use any basic MATLAB operation to implement the algorithm (i.e. you may use any combination of loops, indexing, math, etc.), but avoid “built-in” solution methods — you would not be allowed to use the GaussSeidel function if such a function existed. The function must also test for a number of possible issues. If an issue is...
Python Please (The Fan class) Design a class named Fan to represent a fan. The class...
Python Please (The Fan class) Design a class named Fan to represent a fan. The class contains: ■ Three constants named SLOW, MEDIUM, and FAST with the values 1, 2, and 3 to denote the fan speed. ■ A private int data field named speed that specifies the speed of the fan. ■ A private bool data field named on that specifies whether the fan is on (the default is False). ■ A private float data field named radius that...
Hello. Linear Algebra class. In a linear system of equations, the solution is one of the...
Hello. Linear Algebra class. In a linear system of equations, the solution is one of the possibilities. 1)there is one unique solution(only one) which means the line of the equation interest only one time at a point. 2)there are many solutions (infinity) if the lines of equations lie on one another. 3)there is no solution if the line of the equation are parallel. how to test for each possibility WITHOUT graphing the system of equations using the coefficients in each...
write the code in python Design a class named PersonData with the following member variables: lastName...
write the code in python Design a class named PersonData with the following member variables: lastName firstName address city state zip phone Write the appropriate accessor and mutator functions for these member variables. Next, design a class named CustomerData , which is derived from the PersonData class. The CustomerData class should have the following member variables: customerNumber mailingList The customerNumber variable will be used to hold a unique integer for each customer. The mailingList variable should be a bool ....
python Design a class named IP_address to represent IP address objects. The IP_addressclass contains the following...
python Design a class named IP_address to represent IP address objects. The IP_addressclass contains the following A number of instance variables/fields to store a table of data. You can design them by your own. A constructor that creates a table with the following: a list of data. ip address a integer to indicate the number of elements in the sum_list/freq_list/average_list A get_ip_address() method that returns the ip address For example, consider the following code fragment: ip_key = '192.168.0.24' data_list =[(0,...
Python Design a class named IP_address to represent IP address objects. The IP_addressclass contains the following...
Python Design a class named IP_address to represent IP address objects. The IP_addressclass contains the following A number of instance variables/fields to store a table of data. You can design them on your own. A constructor that creates a table with the following: a list of data. IP address an integer to indicate the number of elements in the sum_list/freq_list/average_list A get_ip_address() method that returns the IP address For example, consider the following code fragment: ip_key = '192.168.0.24' data_list =[(0,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT