我有一个大学作业,我必须平衡以下等式:
NaOH+H2S04-->Na2S04+H20
目前,我对python和编码的了解非常有限。 到目前为止,我试图用矩阵来解这个方程。 看起来我得到的解是a=b=x=y=0 我想我需要将其中一个变量设置为1,然后求解其他三个变量。 我不知道该怎么做, 我查过了,看起来 其他人已经使用了更复杂的代码,而我真的不能遵循它!在
以下是我目前所掌握的情况
#aNaOH + bH2S04 --> xNa2SO4 +y H20
#Na: a=2x
#O: a+4b=4x+y
#H: a+2h = 2y
#S: b = x
#a+0b -2x+0y = 0
#a+4b-4x-y=0
#a+2b+0x-2y=0
#0a +b-x+0y=0
A=array([[1,0,-2,0],
[1,4,-4,-1],
[1,2,0,-2],
[0,1,-1,0]])
b=array([0,0,0,0])
c =linalg.solve(A,b)
print c
0.0.0.0
你可以用这个办法。它适用于任何化学方程式。最后一个系数可以用一行来计算,其中b[i]!=0
H2SO4+NaOH–->;Na2SO4+H2OH2SO4+NaOH–->;Na2SO4+H2O
输出:
[0.5 1。0.5] y=1.000000
我提到了Solve system of linear integer equations in Python,它翻译成
像这样跑
^{pr2}$问题是你已经构造了一个线性系统,其中b是一个零向量。对于这样的系统,总有一个直接的答案,所有变量都是零。因为把一个数乘以零再加上零,结果总是零。在
一个解决方案可能是将1赋给变量。以},因为{}是1。在
a
为例。如果我们指定a = 1
,那么我们将得到b
,x
和{所以现在线性系统是:
或者把它编成代码:
^{pr2}$这意味着:
如果我们把它乘以2,我们得到:
这是正确的。在
相关问题 更多 >
编程相关推荐