有人能建议一种修复方法或者另一种寻找该系统解决方案的路线吗?
特别是我只关心[0,1]x[0,1] 中的解(s,t)。
注意:我在这里寻找两个三次贝塞尔曲线的交点。我需要确保该方法能够找到所有的解,并且最好在合理的时间内完成(对于我的用途,这意味着每对曲线几秒钟)。
我尝试了使用sympy,但solve()和solve_poly_system()都返回了空列表。
这是我的代码:
这将输出:
注意:我在这里寻找两个三次贝塞尔曲线的交点。我需要确保该方法能够找到所有的解,并且最好在合理的时间内完成(对于我的用途,这意味着每对曲线几秒钟)。
我尝试了使用sympy,但solve()和solve_poly_system()都返回了空列表。
这是我的代码:
from sympy.solvers import solve_poly_system, solve
from sympy.abc import s,t
#here are two cubics. I'm looking for their intersection in [0,1]x[0,1]:
cub1 = 600*s**3 - 1037*s**2 + 274*s + 1237*t**3 - 2177*t**2 + 642*t + 77
cub2 = -534*s**3 + 582*s**2 + 437*s + 740*t**3 - 1817*t**2 + 1414*t - 548
#I know such a solution exists (from plotting these curves) and fsolve finds an approximation of it no problem:
from scipy.optimize import fsolve
fcub1 = lambda (s,t): 600*s**3 - 1037*s**2 + 274*s + 1237*t**3 - 2177*t**2 + 642*t + 77
fcub2 = lambda (s,t):-534*s**3 + 582*s**2 + 437*s + 740*t**3 - 1817*t**2 + 1414*t - 548
F = lambda x: [fcub1(x),fcub2(x)]
print 'fsolve gives (s,t) = ' + str(fsolve(F,(0.5,0.5)))
print 'F(s,t) = ' + str(F(fsolve(F,(0.5,0.5))))
#solve returns an empty list
print solve([cub1,cub2])
#solve_poly_system returns a DomainError: can't compute a Groebner basis over RR
print solve_poly_system([cub1,cub2])
这将输出:
fsolve gives (s,t) = [ 0.35114023 0.50444115]
F(s,t) = [4.5474735088646412e-13, 0.0]
[]
[]
感谢阅读!
solve_poly_system
的源代码中,有一行检查顺序:if a <= 2 and b <= 2 and c <= 2 and d <= 2:
- HYRY