如何自动组合不同的方程式
我有9个不同的方程,只有7个未知数。我想生成一个代码,该代码创建7个方程的所有可能系统,并返回所有变量都具有积极结果的情况。 9个方程是:
eq1 = 14*x+7*z-21.71
eq2 = 15*x+11*z+w-38.55
eq3=12*x+8*y+12*z+w-52.92
eq4=12*x+8*y+14*z+t-61.7
eq5=13*x+8*y+15*z+t-69.37
eq6=4*x+17*y+14*r+s-98.32
eq7=4*x+18*y+12*w+s-130.91
eq8=4*x+18*y+15*w+2*t-165.45
eq9=4*x+18*y+12*w+2*s-168.16
I have 9 different equations that contain only 7 unknowns. I would like to generate a code that creates all the possible systems of 7 equations and return the cases in which all the variables have a positive result. The 9 equations are:
eq1 = 14*x+7*z-21.71
eq2 = 15*x+11*z+w-38.55
eq3=12*x+8*y+12*z+w-52.92
eq4=12*x+8*y+14*z+t-61.7
eq5=13*x+8*y+15*z+t-69.37
eq6=4*x+17*y+14*r+s-98.32
eq7=4*x+18*y+12*w+s-130.91
eq8=4*x+18*y+15*w+2*t-165.45
eq9=4*x+18*y+12*w+2*s-168.16
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
改编自 this 回答
您想做的事情是通过迭代的所有仅具有
7
方程式的组合。您可以使用嵌套循环进行此操作,但是它会变得非常丑陋,因为您将拥有7
嵌套。itertools
python中的库(标准库)具有以下循环的内置方法,因此,如果创建一个方程列表,则可以通过执行以下system < /代码>将是系统中包含
7
方程的元组。从那里使用任何要解决的求解技术,并确定所有输出是否为正(即numpy
和矩阵方程)Adapted from this answer
What you want to do is iterate through all the combinations that only have
7
equations. You can do this with nested loops but it will get very ugly as you will have7
nests.itertools
library in python (standard library) has a built in method for looping like this, so if you create a list of equations, you can iterate through all unique systems by doing the followingsystem
is going to be a tuple containing the7
equations in the system. From there use whatever solving technique you want to solve them and determine if all outputs are positive (i.e.numpy
and matrix equations)