## 3 Balancing Chemical Equations Using Iterations
### Balancing Chemical Equations Using Iterative Methods
```
1:Id=IdentityMatrix[n];s=(Id-X.A).ConstantArray[1,n];s=Rationalize[s,10^(-300)];c=s*LCM@@Denominator/@s; (* MultiplysbytheLeastCommonMultipleofdenominatorsins*) s=c/Min@@Numerator/@c (* DividecbytheMinimumofnumeratorsinc*)
```  
**Algorithm 4** General algorithm for balancing chemical equations by an iterative solver. ```
1:Id=IdentityMatrix[n];s=(Id-X.A).ConstantArray[1,n];s=Rationalize[s,10^(-300)];c=s*LCM@@Denominator/@s; (* MultiplysbytheLeastCommonMultipleofdenominatorsins*) s=c/Min@@Numerator/@c (* DividecbytheMinimumofnumeratorsinc*)The standard _Mathematica_ function Rationalize[x,dx] yields the rational number with the smallest denominator within a given tolerance \(dx\) of \(x\). Sometimes, to avoid the influence of round-off errors and possible errors caused by the usage of the function Rationalize, it is necessary to perform iterative steps with a very high precision. An improvement of the vector \(s\) can be attained as follows. It is possible to propose an amplification of the vector \(s=\left(I-A^{\dagger}A\right)c\), where \(c\) is an \(n\)-dimensional column vector. The improvement can be obtained using \(s=\left(I-A^{\dagger}A\right)\left(\left(I-A^{\dagger}A\right)c\right)\). In the practical implementation, it is necessary to replace the expression s = (Id - X.A).ConstantArray[1, n] by s = (Id - X.A). ((Id - X.A).ConstantArray[1, n]). This replacement can be explained by the fact that \(A(I-A^{\dagger}A)s\) is closer to the zero vector zero than \(As\). ### Balancing Chemical Equations in Symbolic Form

As was explained in [6], balancing \(\aleph\) chemical reactions that possess atoms with fractional oxidation numbers and non-unique coefficients is an extremely hard problem in chemistry. The case when the system Equation (21) is not uniquely determined can be resolved using the _Mathematica_ function Reduce. If a \(\aleph\) chemical reaction includes \(n\) reaction molecules and \(m\) reaction elements, then the reaction matrix \(A\) is of the order \(m\times n\). In the case \(n>m\), the reaction has \(\binom{n}{m}\) general solutions. All of them can be found applying the following expression:

Reduce[A. {{x1},{x2},...,{xn}} == {0,0,...,0},{xk1, xk2,...,xkm}] where the zero vector in the right-hand side is of the length \(m\) and \(\{xk1,xk2,...,xkm\}\) is the list of dependent variables. ## 4 Experimental Results

Let us denote the iterations Equation (3) by NM (Newton's Method), the iterations Equation (4) by CM (Chebyshev's Method) and Equation (9) by PM (Proposed Method). Here, we apply different methods in the Mathematica 10 environment to compute some generalized inverses and to show the superiority of our scheme(s). We also denote the hybrid algorithm given in [22] by HAL (Householder Algorithm) and our Algorithm 1 is denoted by APM (Accelerated Proposed Method). Throughout the paper the computer characteristics are Microsoft Windows XP Intel(R), Pentium(R) 4 CPU, 3.20 GHz with 4 GB of RAM, unless stated otherwise (as in the end of Example 1). ### Numerical Experiments on Randomly-Generated Matrices

**Example 1**. : _[_22_]_ _In this numerical experiment, we compute the Moore-Penrose inverse of a dense, randomly-generated \(m\times n=800\times 810\) matrix, which is defined as follows:_

m = 800; n = 810; SeedRandom[12345]; A = RandomReal[{-10, 10}, {m, n}];The numerical results corresponding to the number of iterations and the CPU time are illustrated in Table 1, wherein IT denotes the number of iterative steps. It shows that APM with \(m=2\) and five inner loops, while \(p=2\), is superior to the other existing methods. We employed HAL with \(m=2\) and eight inner loops. Note that the initial matrix is chosen as \(X_{0}=\frac{2}{\|A\|_{F}^{2}}A^{*}\), while the stopping criterion is defined by \(\frac{\|X_{k+1}-X_{k}\|_{\infty}}{\|X_{k+1}\|_{\infty}}<10^{-300}\).