如何得到辛解以给出系数较小的解

2024-09-27 21:33:25 发布

您现在位置:Python中文网/ 问答频道 /正文

考虑下面的例子丢番图方程

-118w + 989x + 918y  -512z == 0

您可以通过以下方式解决此问题:

import sympy
from sympy.solvers.diophantine import diophantine 
w, x, y, z = sympy.symbols('w x y z')
a, b, c, d = -118, -989, 918, -512
diof = list(diophantine(a*w -b*x +c*y -d*z ))[0]
print(diof)

其中:

(t_0, -118*t_0 + 2*t_1, 1690468*t_0 - 28425*t_1 + 256*t_2, -3031184*t_0 + 50969*t_1 - 459*t_2)

说明:此解决方案允许您自由选择三个整数t_0、t_1、t_2,并从中计算w、x、y、z的值

这很好,只是系数总是比需要的大得多。如果你在Mathematica中求解相同的系统,你会得到:

x = 2 c_2, y = 9 c_2 + 256 c_3 + 81 w, z = 20 c_2 + 459 c_3 + 145 w, c_2 element Z and c_3 element Z

或:

enter image description here

对于系数同样小的线性丢番图方程,有可能得到辛解吗


Tags: fromimport方式element解决方案list例子方程

热门问题