Appendix J — Solving Algebraic/Transcendental Equations
This appendix examines the numerical solution of sets of algebraic/transcendental equations (ATEs). There are numerous software packages that include an ATE solver (function that solves a set of ATEs numerically). While the details differ from one software package to another, the vast majority of ATE solvers require the same input, use it the same way, and return equivalent results. The information provided here should be sufficient to understand the examples presented in Reaction Engineering Basics and to solve sets of ATEs using software of one’s choosing. Readers seeking a more complete understanding should consult a numerical methods reference book or take a course on numerical methods.
J.1 Identifying ATEs and Preparing to Solve Them Numerically
In Reaction Engineering Basics, almost any equation that does not contain an ordinary derivative or a partial derivative is likely an ATE. Slightly more specifically, a set of ATEs is a group of 1 or more mathematical equations that may involve or contain math operations (addition, subtraction, multiplication, and division), quantities raised to powers, and transcendental functions. Exponential functions are the most common transcendental functions appearing in the ATEs found in Reaction Engineering Basics. They arise any time an equation includes a rate coefficient that displays Arrhenius temperature dependence, Equation 4.8.
The quantities that may appear in a set of \(N\) ATEs can be classified as (a) known constants, (b) the ATE unknowns, and (c) other unknowns. If there are \(N\) ATEs in the set, then there must be \(N\) ATE unknowns. The ATE unknowns are the quantities that are found by solving the ATEs. In reaction engineering analyses, it often happens that unknowns other than the ATE unknowns also appear in a set of ATEs. Before the set of ATEs can be solved numerically, the values of these other unknowns must be calculated or provided as will be described subsequently.
In preparation for numerically solving a set of ATEs, an ATE residual should be defined for each equation in the set. To do so, rearrange the ATE so that there is a zero on one side of the equation. The ATE residual is equal to the non-zero side of the resulting equation. In general each residual can be a function of all of the ATE unknowns. If a set of values for the \(N\) ATE unknowns is used to evaluate the \(N\) residuals, and if the \(N\) residuals all equal zero, then that set of ATE unknowns is one solution of the ATEs. It should be noted that the ATEs may have additional solutions.
J.2 ATE Solvers
As noted in the introduction, an ATE solver is a function that solves a set of ATEs numerically. Typically, an ATE solver must be provided with two inputs. The first is an initial guess for the ATE unknowns. The second is a residuals function. The residuals function receives a guess for the ATE unknowns and uses them to evaluate and return the corresponding values of the ATE residuals. Effectively, the ATE solver uses the initial guess and resuduals function to find a solution of ATEs by trial and error.
- It tests the initial guess by calling the residuals function and determining whether all of the ATE residuals equal zero.
- If the initial guess does not solve the ATEs, the ATE solver generates an improved guess and tests that.
- The improved guess will not be an exact solution (unless the ATEs are linear equations), but usually it will be closer to the solution than the previous guess.
- The ATE solver keeps generating improved guesses and testing them until no further improvement is possible.
- It then returns the final, most-improved guess as a solution of the ATEs.
J.2.1 Convergence and Solver Issues
So, the numerical solution of a set of ATEs is an iterative process, and ideally, the ATE residuals should get closer and closer to zero with each iteration. This is called convergence to a solution. Typically, the solution returned by the solver will not be exact, but it will be “very close” to the exact solution. Put differently, when a converged solution is found, the difference between the solution returned by the solver and the exact solution is negligible.
Sometimes the solver is unable to converge to the point where the residuals are “very close” to zero. In this situation, the solver eventually has to quit without finding a converged solution. Typically it will print an error message or return a flag variable, and that variable will indicate whether or not a converged solution was obtained.
When the ATE solver is not able to converge to a solution, it is often because the guess provided to the solver wasn’t close enough to a solution. One remedy to this issue is to make a different initial guess and try again to solve the ATEs. Examining the ATE residuals can sometimes help in making a new initial guess. For example, if all of the residuals are large negative numbers, that may suggest how to change the initial guess so that the ATE residuals become less negative (or even slightly positive) and closer to zero.
A singularity in one or more of the residuals could also prevent the ATE solver from converging. For example, fractions that contain one or more unknowns in the denominator may appear in the residuals. If a guess for the ATE unknowns causes such a denominator to equal zero, the residual becomes infinite and the solver fails to converge. Potential singularities of this kind can be removed by re-defining the ATE residuals. To do so, after rearranging each ATE so there is a zero on one side of the equation, multiply both sides of the equation by each denominator that contains an unknown. Then use the resulting non-zero side of the equation as the ATE residual.
Finally, as already noted, sets of ATEs can have more than one solution. For example, a quadratic polynomial has two solutions. If a set of ATEs has multiple solutions, most ATE solvers will only find one of them. To find other solutions, the solver should be re-started using a different initial guess.
J.2.2 The Residuals Function
The ATE solver is part of a mathematics software package. It must call the residuals function which is written by the engineer who needs to solve a set of ATEs. While the argument to the response function is always always an initial guess for the ATE unknowns and the corresponding values of the ATE residuals are always returned, the mathematics software package specifies the details (e. g. are the guesses for the ATE unknowns passed as individual arguments or are they combined into a vector, etc.). The person calling the ATE solver must write the residuals function so it conforms to those specifications.
The calculations performed within the residuals function are straightforward. Recall that the residuals expressions can contain known constants, the ATE unknowns, and other unknowns. Values for the ATE unknowns are passed to the residuals function, and known constants are available. Therefore the only thing that the residuals function needs to do before it can evaluate the residuals is to calculate the other unknowns. Very often the other unknowns can be calculated using known constants and the ATE unknowns. However if it is not possible to calculate the other unknows within the residuals function, they must be provided to it.
Providing unknown constants to the residuals function forces a computer programming choice that won’t be discussed here. The issue is that the other unknowns cannot be passed to the residuals function as arguments. The arguments that can be passed to the residuals function are fixed by the mathematics software package being used and are limited to guesses for the ATE unknowns. As a consequence, any other unknowns that cannot be calculated within the residuals function will need to be provided by other means. The documentation for the mathematics software package may suggest a preferred way to do this such as by using a global variable or by using a pass-through function. Once the other constants are calculated or made available, all that remains to be done within the residuals function is to evaluate the ATE residuals and return them.
J.3 Mathematical Formulation of the Numerical Solution of a Set of ATEs
Once the set of ATEs to be solved and the ATE unknowns to be found by solving them have been identified, the numerical solution of the ATEs can be formulated. The first step actually is to formulate the ATE residuals function. The ATE residuals function specification should list the arguments to be passed to it (guesses for the ATE unknowns), the quantities it will return (the ATE residuals), and any other unknowns that must be provided to it. It should also include the algorithm, i. e. the sequence of calculations needed to evaluate the return values assuming the given and known constants, arguments, and additional required input are available.
The remainder of the formulation focuses on the ATE solver. This part begins with a guess for the values of the ATE unknowns. In reaction engineering the ATE unknowns are often outlet molar flow rates, outlet temperature and outlet exchange fluid temperature. One approach to guessing the unknowns is to make small perturbations to the inlet values. Solver convergence is often most sensitive to temperatures, so if the reaction is exothermic, one might guess that the outlet temperature is a few degrees greater than the inlet temperature and that the outlet exchange fluid is a few degrees lower than its inlet. For an endothermic reaction the temperatures would change in the opposite directions. If the solver fails to converge, the guesses can be increased until it does. The important thing to remember is that they are only guesses; one shouldn’t try to solve the ATEs in order to guess the solution.
The next thing that must be done is to make any other unknowns that can’t be calculated within the ATE residuals function available to it as discussed above. Once that has been accomplished, all that remains is to call the solver. The arguments passed to it will be the name of the ATE residuals function and the guess for the ATE unknowns. The values that will be returned by the solver should be identified. While not necessarily part of the mathematical formulation, the actual computer code should next check that the solver did converge. Also, when executing the code one must remember that there could be other solutions.
J.4 Example
The following example illustrates the mathematical formulation of a set of ATEs as described above.
J.4.1 Formulation of the Solution of a Set Steady-State CSTR Design Equations
A reaction engineer is modeling an isothermal steady-state CSTR wherein reaction (1) occurs. The engineer has generated the reactor design equations, written them in the form of residuals, equations (2) through (5), and needs to solve them to find the outlet molar flow rates, \(\dot{n}_{A,1}\), \(\dot{n}_{B,1}\), \(\dot{n}_{Y,1}\), and \(\dot{n}_{Z,1}\). The rate, \(r\), can be calculated using equations (6) through (8). The rate coefficient, \(k\), volume, \(V\), and volumetric flow rate, \(\dot{V}\), are known constants. The inlet molar flow rates, \(\dot{n}_{A,0}\), \(\dot{n}_{B,0}\), \(\dot{n}_{Y,0}\), and \(\dot{n}_{Z,0}\), are constants, but they cannot be calculated from the information that will be available to the residuals function. Formulate the numerical solution of equations (2) through (5).
\[ A + B \rightarrow Y + Z \tag{1} \]
\[ 0 = \epsilon_1 = \dot{n}_{A,0} - \dot{n}_{A,1} - rV \tag{2} \]
\[ 0 = \epsilon_2 = \dot{n}_{B,0} - \dot{n}_{B,1} - rV \tag{3} \]
\[ 0 = \epsilon_3 = \dot{n}_{Y,0} - \dot{n}_{Y,1} + rV \tag{4} \]
\[ 0 = \epsilon_4 = \dot{n}_{Z,0} - \dot{n}_{Z,1} + rV \tag{5} \]
\[ r = k C_A C_B \tag{6} \]
\[ C_A = \left(\frac{\dot{n}_{A,1}}{\dot{V}}\right) \tag{7} \]
\[ C_B = \left(\frac{\dot{n}_{B,1}}{\dot{V}}\right) \tag{8} \]
Residuals Function
\(\qquad\) Arguments: \(\dot{n}_{A,1}\), \(\dot{n}_{B,1}\), \(\dot{n}_{Y,1}\), and \(\dot{n}_{Z,1}\)
\(\qquad\) Other Input: \(\dot{n}_{A,0}\), \(\dot{n}_{B,0}\), \(\dot{n}_{Y,0}\), and \(\dot{n}_{Z,0}\)
\(\qquad\) Return Variables: \(\epsilon_1\), \(\epsilon_2\), \(\epsilon_3\), and \(\epsilon_4\)
\(\qquad\) Algorithm:
\(\qquad \qquad\) 1. Calculate any other unknowns.
\[ C_A = \left(\frac{\dot{n}_{A,1}}{\dot{V}}\right) \tag{7} \]
\[ C_B = \left(\frac{\dot{n}_{B,1}}{\dot{V}}\right) \tag{8} \]
\[ r = k C_A C_B \tag{6} \]
\(\qquad \qquad\) 2. Evaluate and return \(\epsilon_1\), \(\epsilon_2\), \(\epsilon_3\), and \(\epsilon_4\) using equations (2) - (5).
Solving the Design Equations
- Make an initial guess for the ATE unknowns.
\[ \dot{n}_{A,1,guess} = \frac{\dot{n}_{A,0}}{2} \]
\[ \dot{n}_{B,1,guess} = \dot{n}_{B,0} - \frac{\dot{n}_{A,0}}{2} \]
\[ \dot{n}_{Y,1,guess} = \dot{n}_{Y,0} + \frac{\dot{n}_{A,0}}{2} \]
\[ \dot{n}_{Z,1,guess} = \dot{n}_{Z,0} + \frac{\dot{n}_{A,0}}{2} \]
Make \(\dot{n}_{A,0}\), \(\dot{n}_{B,0}\), \(\dot{n}_{Y,0}\), and \(\dot{n}_{Z,0}\) available to the residuals function.
Call an ATE solver.
Pass \(\dot{n}_{A,1,guess}\), \(\dot{n}_{B,1,guess}\), \(\dot{n}_{Y,1,guess}\), \(\dot{n}_{Z,1,guess}\), and the name of the residuals function (above) as arguments.
Assuming the solver converges, receive one set of values of \(\dot{n}_{A,1}\), \(\dot{n}_{B,1}\), \(\dot{n}_{Y,1}\), and \(\dot{n}_{Z,1}\) that solve the design equations; there could be other solutions.
J.5 Symbols Used in Appendix J
Symbol | Meaning |
---|---|
\(k\) | Rate coefficient. |
\(\dot n_i\) | Molar flow rate of reagent \(i\); an additional subscripted \(0\) denotes the inlet molar flow rate or a subscripted \(1\), the outlet molar flow rate. |
\(r\) | Rate of reaction. |
\(C_i\) | Molar concentration of reagent \(i\). |
\(N\) | Number of ATEs being solved and number of ATE unknowns being found. |
\(V\) | Volume of reacting fluid. |
\(\dot{V}\) | Volumetric flow rate. |
\(\epsilon_i\) | Residual for the \(i^{th}\) ATE. |