通过程序求解多种反应之间的化学摩尔比

发布于 2025-02-13 10:42:06 字数 594 浏览 2 评论 0原文

考虑反应:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

随遇而安 2025-02-20 10:42:06

对我来说,它看起来更像是图形问题,而不是线性方程求解。对此进行编码会很乏味,但是我可以提供简单的算法,希望这会有所帮助。

  1. 建立加权的有向图,其中顶点是化学物质,边缘描述了特定摩尔比的反应。

  2. 找到两个物质之间的路径。

  3. 计算路径重量的产品,这是您的答案。

注意:

  • 有很多路径可以找到算法,例如BFS,DFS,Dijkstra。 https://en.wikipedia.org/wiki/pathfinding
  • 参见 物质之间的多个路径,这意味着可以通过多种方式合成化学物质,您可能需要重量最小的路径
  • 才能弄清楚出去,如何处理循环

”在此处输入图像说明”

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.

  1. Build weighted directed graph, where vertices are chemical substances and edges describe reactions with specific molar ratio.

  2. Find path between two substances.

  3. Compute product of path weights, this is your answer.

Notes:

  • there a lot of path finding algorithms, for example BFS, DFS, Dijkstra's. See https://en.wikipedia.org/wiki/Pathfinding
  • can happen, that there is multiple paths between substances, it means that chemical substance can be synthesised in multiple ways, probably you need path with least weight
  • need to figure out, what to do with cycles

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文