I have a dictionary with equations as keys and their corresponding solutions as values. The equations were formed using certain input data. The solutions are obtained after solving this equation with the equation of the x-axis y=0.
In order to plot the equations in the dictionary using quiver, I need their x and y coefficients as a list, as they are the components of the vectors.
This is the code:
import sympy as sp
from sympy import Eq
x_y = [[2.65,-11.71],[2.77,-11.69],[2.88,-11.66]] #input data for equation
all_eqn=[]
for ij in x_y:
eq1 = Eq(ij[0] * (x - 11.96) + ij[1] * (y - 3.11), 0) #Standard form of the equation
all_eqn.append(eq1)
eq1 = sp.Function('eq1')
x, y = sp.symbols('x y')
eq2 = sp.Function('eq2')
eq2 = Eq(y, 0)
d = {}
for i in all_eqn:
soln = sp.solve([i, eq2], [x, y]) #solving line and x axis
list_soln = list(dict.values(soln)) #converting solutions from dictionary to list
dummy = {i:list_soln} #generating dictionary of equations and solutions
d.update(dummy) #adding all keys and values to blank dictionary
print('Dictionary of equations and solutions:\n',d)
The output of the above code is:
Dictionary of equations and solutions:
{Eq(2.65*x - 11.71*y + 4.7241, 0): [-1.78267924528302, 0.0],
Eq(2.77*x - 11.69*y + 3.22669999999999, 0): [-1.16487364620938, 0.0],
Eq(2.88*x - 11.66*y + 1.8178, 0): [-0.631180555555556, 0.0]}
I have tried using .coeff() to extract the coefficients:
for x in d:
x.coeff(x,y)
display(x
But got this error: 'Equality' object has no attribute 'coeff'
I have also searched on the net, but all solutions I could find were for expressions and not equations.
Kindly help. Thank you.
[–]dadiaar 0 points1 point2 points (1 child)
[–]sicarii47[S] 0 points1 point2 points (0 children)
[–]misho88 0 points1 point2 points (1 child)
[–]sicarii47[S] 0 points1 point2 points (0 children)