from sympy import *
Rfinal = dict()
Bfinal = dict()
x, y = symbols('x y')
Red= [(1,1),(2,1),(4,2),(2,4), (-1,4)]
Blue= [(-2,-1),(-1,-2),(-3,-2),(-3,-1),(1,-3)]
Lines=["(1*x)+(1*y)+0","(1*x)-(1*y)+0","(1*x)+(0*y)-3","(0*x)+(1*y)-0.5"]
for exp in Lines:
for a,b in Red:
d = exp.subs(x,a).subs(y,b)
if d > 0:
Rfinal['(a,b)'] = positivepoint
elif d == 0:
Rfinal['(a,b)'] = pointontheline
else:
Rfinal['(a,b)'] = negativepoint
for exp in Lines:
for p,q in Blue:
d = exp.subs(x,a).subs(y,b)
if d > 0:
Bfinal['(p,q)'] = positivepoint
elif d == 0:
Bfinal['(p,q)'] = pointontheline
else:
Bfinal['(p,q)'] = negativepoint
error 'str' object has no attribute 'subs'*
IIUC
您的行是字符串,而不是SymPy表达式。可以将它们转换为以下表达式:
但是最好删除表达式周围的引号,因为您已经将
x
和y
定义为符号(您可能需要删除引号 也围绕着“(a,b)”和“(p,q)”
相关问题 更多 >
编程相关推荐