solving algebraic equations in python

import numpy as np
def get_list(n):
    f=[]
    for j in range(1,n+1):
        a=int(input("enter values"))
        f=f+[a]
    return f
    
def get_matrix(n,m):
    sum=np.array([get_list(n*m)])
    return sum.reshape(n,m)


def que_equation(n):
    sum=[]
    
    for i in range(1,n+1):
        print("enter the list A",i)
        sum=sum + get_list(n)
    return sum


r=int(input("no. of equ"))  
e=que_equation(r)           #simply create a list having all the components of the given question.
W=np.array(e)               #W be the array of that list.
U=W.reshape(int(r),int(r))  #it will separate or arrange the que matrix by their rows and columns.          
S=int(input("Enter the solution matrix"))
P=get_matrix(S,1)
A=np.linalg.solve(U,P)
print("sol is given by ",A)

suppose we have the following equation:-

Step By step print discussions:-
1.printing the list of the components of equation.

2.Creating array from that list.

3.Finally equation matrix.

4.printing the solution matrix that is being given in the right hand side of the equation.

5.Hence,solving the equations.

Leave a Reply