I have the column routine working, but I am still testing various cases. Since it may not be in its final form, I am delaying its presentation. Instead, this post will provide some tips on programming to avoid errors.
Avoiding unrealistic values
Numerical methods may momentarily produce unrealistic values such as zero or negative flows. Such results can then upset the algorithm producing further errors such as imaginary numbers or division by zero. Since most processes can't produce a true zero concentration, for example, the error can be avoided by limiting the variable to a very small finite number.
Using Mathcad's "on error" function
The "on error" function can be used to avoid termination due to error. In the example below, the normal assignment for x4_new is the one on the right of "on error". If that calculation results in an error then the alternative assignment on the left is used.
In the stage_N routine shown in the previous post, I had a statement that created a divide by zero error. The first statement below was the original version. The error occurred due to to the first term in the denominator. The problem was corrected by multiplying the numerator and denominator by the "out" variable. The improved version is the second statement.