通过程序求解多种反应之间的化学摩尔比
考虑反应:
C6.H12.O6+6O2-> 6H2.O1+6C1.O2(葡萄糖+6 氧气 - 氧气 - 6水+6 二氧化碳)
2C1.H4.O1+C1 。 1,3-二羟基丙酮 +水)
如何通过编程方式找出两种反应之间的两种化合物的摩尔比? (例如,在这种情况下,葡萄糖和1,3-二羟基丙烷之间的摩尔比)。使用一个方程式,问题变得琐碎(该比率只是substance1/cofficificofsubstance2),但是随着一个以上的等式,问题变得更加困难。我已经实施了解析功能来解析化学反应(并平衡它们)。我认为要走的方法是将每个物质设置为自己的变量,然后将所有物质与系数相同的系数设置在一个方程中,然后求解比率。例如,对于上方对,方程将为:
1*a = 6*b = 6*c = 6*d
2*e = d = f = c
因此:葡萄糖(1*a)和1,3-二羟基丙酮(F)之间的比率为:
1*a=6*d
d=f
a=6*f
因此,摩尔比为1/6。
我不知道该如何编程执行此操作。我希望在python3中使用解决方案,但无论编程语言如何,任何帮助当然都会受到赞赏。
Consider the reactions:
C6.H12.O6+6O2->6H2.O1+6C1.O2 (glucose + 6oxygen ->6 water + 6carbon dioxide)
2C1.H4.O1+C1.O2->C3.H6.O3+H2.O1 (2*methanol + carbon dioxide -> 1,3-dihydroxypropanone + water)
How can I programmatically figure out the molar ratio of two compounds between two reactions? (For example in this case the molar ratio between glucose and 1,3-dihydroxypropane). With one equation the problem becomes trivial (the ratio is just coefficientofsubstance1/coefficientofsubstance2), but with more than one equation the problem becomes more difficult. I have already implemented the parsing function to parse the chemical reactions (and to balance them). I think the way to go is to set every substance to its own variable and then set all of the substances in one equation with coefficients equal to each other and then solve for the ratio. For example for the upper pair of equations the equations would be:
1*a = 6*b = 6*c = 6*d
2*e = d = f = c
therefore the ratio between glucose (1*a) and 1,3-dihydroxypropanone (f) would be:
1*a=6*d
d=f
a=6*f
therefore the molar ratio is 1/6.
I do not know how to do this programmatically. I would like the solution in python3 preferably, but any help would of course be appreciated no matter the programming language.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对我来说,它看起来更像是图形问题,而不是线性方程求解。对此进行编码会很乏味,但是我可以提供简单的算法,希望这会有所帮助。
建立加权的有向图,其中顶点是化学物质,边缘描述了特定摩尔比的反应。
找到两个物质之间的路径。
计算路径重量的产品,这是您的答案。
注意:
For me it looks more like graph problem, not linear equation solving. Coding this would be tedious, but I can provide with simple algorithm, hope this helps.
Build weighted directed graph, where vertices are chemical substances and edges describe reactions with specific molar ratio.
Find path between two substances.
Compute product of path weights, this is your answer.
Notes: