Sage 中两个方程组的实数解

Real solutions to a system of two equations in Sage

我有以下代码 (SageMath 9.3),它确定了共同点 2个方程组的解(第一个代表曲线,第二个代表水平线;公共解代表它们的交点):

x, y = var('x, y')
p1 = y^2 - x^3 + x - 1 == 0
p2 = y - 10 == 0
sols = solve([p1, p2], x, y)
sols

输出:

[[x == 4.698114754098361, y == 10.0],
 [x == (-2.349057376230034 + 3.943882816522595*I), y == 10.0],
 [x == (-2.349057376230034 - 3.943882816522595*I), y == 10.0]]

我的问题:如何更改此设置以便我只获得真正的解决方案?

椭圆曲线与水平线的交点

这里有三种找到交点的方法, 或其 x 坐标。可能还有更多方法!

使用求解

一种方法是像您一样找到所有复杂的解决方案:

sage: x, y = var('x, y')
sage: p1 = y^2 - x^3 + x - 1 == 0
sage: p2 = y - 10 == 0
sage: sols = solve([p1, p2], x, y, solution_dict=True)
sage: sols

然后提取真实的:

sage: real_sols = [sol for sol in sols if all(v in RR for v in sol.values())]
sage: real_sols
[{x: 4.698114754098361, y: 10.0}]

使用多项式

另一种方法是定义多项式:

sage: x = polygen(ZZ)
sage: p = x^3 + (-1)*x + 1
sage: p
x^3 - x + 1

并在代数实数上找到它的根:

sage: (p - 10^2).roots(AA, multiplicities=False)
[4.698114752460068?]

或超过浮点实数:

sage: (p - 10^2).roots(RR, multiplicities=False)
[4.69811475246007]

使用椭圆曲线

另一种方法是定义椭圆曲线:

sage: E = EllipticCurve([-1, 1])
sage: E
Elliptic Curve defined by y^2 = x^3 - x + 1 over Rational Field

然后它的环境 space:

sage: P = E.ambient_space()
sage: P
Projective Space of dimension 2 over Rational Field

那么相关的多项式变量:

sage: P.gens()
(x, y, z)
sage: x, y, z = P.gens()

然后构造“y = 10”对应的投影线:

sage: L = P.curve([y - 10*z])
sage: L
Projective Plane Curve over Rational Field defined by y - 10*z

然后计算椭圆曲线的交点 代数实数上的线:

sage: E.intersection_points(L, F=AA)
[(4.698114752460068? : 10 : 1)]