帮忙使用化学平衡仪吗? (从数组列表到矩阵的转换)在java中

发布于 2024-10-09 19:27:37 字数 393 浏览 8 评论 0原文

我正在制作一个平衡化学方程式的java应用程序。我循环遍历每个术语并创建两个数组列表。在一个数组列表中,我拥有所有元素的集合。例如(在第一项中)如果方程为 C6H12O6+O2=CO2+H2O,则数组列表将具有 {C, H, O}。在另一个中,我有相应的数字,因此它将包含 {6,12,6}。我需要将所有这些组合起来形成一个矩阵(3 x 4),即:

(0,0) = 6 (1,0) = 12 (2,0) = 6 (0,1) = 0 (1,1) = 0 (2,1) = 2 (0,2) = 1 (1,2) = 0 (2,2) = 2 (0,3) = 0 (1,3) = 2 (2,3) = 1

上面的矩阵设计为第 0 行是 C,第 1 行是 H,第 2 行是 O。列是项 (0、1、2 和 3)

对于转换数组列表转换为矩阵?

I am making a java application that balances chemical equations. I loop through each term and create two arraylists. In one arraylist, I have the set of all of the elements. For example (in the first term) if the equation is C6H12O6+O2=CO2+H2O, the arraylist will have {C, H, O}. In another, I have the corresponding numbers, so it will contain {6,12,6}. I need to combine all of these to form a matrix (3 by 4), which would be:

(0,0) = 6
(1,0) = 12
(2,0) = 6
(0,1) = 0
(1,1) = 0
(2,1) = 2
(0,2) = 1
(1,2) = 0
(2,2) = 2
(0,3) = 0
(1,3) = 2
(2,3) = 1

The matrix above is designed so that row 0 is C, row 1 is H, and row 2 is O. The columns are the terms (0, 1, 2, and 3)

Any suggestions for converting the arraylists into a matrix?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

挽梦忆笙歌 2024-10-16 19:27:37

如果您这样做是为了好玩或为了一个项目,那很好。如果您这样做是为了让化学家使用真正的可扩展应用程序,那么您将需要满足 > 100 种元素、多种试剂和产品以及少量。有很多开源 Java 化学库,我很乐意向您介绍。不要重新发明轮子。请参阅 http://www.blueobelisk.org

要认真做到这一点,需要 Ugi 开发的键/电子矩阵。你最好的地方是 Ugi 自己的论文:
www.iupac.org/publications/pac/1978/pdf/5011x1303.pdf

参见 - 例如第 1307 页。

编辑:
对于当前的问题来说,这太过分了!

一个简单的矩阵方法将包括 2 个耦合矩阵 R(反应物)和 P(产物),其中 Nelem(例如 100)列表示已知元素,行数不定(nR,nP)表示许多反应物和产物。因此,矩阵通常不会具有相同的维数。反应物[nR][nelem]和产物[nP][nelem]。乘法器 nreact[nR] 和 nprod[nP] 也有两个列向量。请注意,一般化学式和乘数通常是整数,但不一定是(化合物可能不具有简单的元素整数比)。

我将使用我自己的 CMLFormula 和 CMLReaction Java 类(请参阅 http://www.xml-cml.org )来解决这个问题。欢迎您从这里开始 - 这会让生活变得更轻松

If you are doing this for fun or a project, fine. If you are doing this for a real extensible application to be used by chemists then you will need to cater for > 100 elements, many reagents and products and fractional amounts. There are a lot of Open Source Java chemistry libraries and I'd be happy to introduce you. Do not re-invent the wheel. See http://www.blueobelisk.org

To do this seriously requires a Bond/Electron matrix as developed by Ugi. Your best place is Ugi's own paper:
www.iupac.org/publications/pac/1978/pdf/5011x1303.pdf

see - e.g. p 1307.

EDIT:
This is overkill for the current problem!

A simple matrix approach would include 2 coupled matrices R (reactants) and P (products) with nelem (say 100) columns for known elements and an indefinite number of rows (nR, nP) as many reactants and products. The matrices would therefore generally not be of equal dimensions. reactant[nR][nelem] and product [nP][nelem]. There would also be two column vectors for the multipliers nreact[nR] and nprod[nP]. Note that in general chemical formulae and multipliers are commonly integral but need not be (may compounds do not have simple integer ratios of elements).

I would use my own CMLFormula and CMLReaction Java classed (see http://www.xml-cml.org) to tackle this. You are welcome to start there - it will make life easier

远昼 2024-10-16 19:27:37

您可以用数组表示矩阵:将每一行视为列数据的数组:

[[6 12 6], 
 [0 0  2], 
 [1 0  2], 
 [0 2  1]]

这样,您的矩阵点就是对给定点处另一个数组内的数组位置的引用。换句话说:(

matrix[0][2] == 2

对于第一个数组(0),第二个位置(1))

不过,我不能支持或反对你的化学逻辑。 :)

You can represent a matrix by arrays: think of each row as an array of column data:

[[6 12 6], 
 [0 0  2], 
 [1 0  2], 
 [0 2  1]]

This way, your matrix point is a reference to the array position inside another array at a given point. in other words:

matrix[0][2] == 2

(for the first array (0), second position (1))

I can't speak for or against your logic in the chemistry, though. :)

离线来电— 2024-10-16 19:27:37

如果您想在 Java 中进行良好的矩阵运算,请查看 JAMA (Java Matrix)

If you want good matrix operations in java look at JAMA (Java Matrix)

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