The solve block for the SI function is written in vector/matrix notation. At a few points, this was a challenge. Making it even more difficult is the fact that loops on an index aren't allowed within the solve block, with one exception...the built in vectorize function.
The vectorize function
Mathcad provides a vectorization function that performs a set of mathematical operations on vectors of equal length by looping through the vector index one at a time and placing the results in a vector of the same length. The example below demonstrates for a simple multiplication.
In the above example, the vectorization is equivalent to
for i = 0, 1, 2
Zi = Xi x Yi
There can be more than one operation under the arrow and the operations may be non-linear, such as square roots or exponents. There also may be any number of vectors involved as long as they all have the same number of elements.
I needed to multiply each element of a molar production vector by the molecular weight of the component for each element in the production vector. This operation would obtain the mass production rates from the molar production rates of each species.
A dot product of the molecular weight vector, Mw, and the molar production rate vector, Rxn0, would result in the total mass production rate, a scalar, instead of a vector of individual rates.
The vectorize function also can't be used because the Rxn0 vector is actually a function with the vector of compositions as one argument. The vectorize operation would use only one element at a time in the function call to Rxn0, instead of the entire vector as needed. This results in an error.
The Mw vector was used to create a diagonal matrix with the molecular weight on the diagonal. Mathcad provides a "diag" function for this purpose.
I assigned the result of the diagonal operation to a constant, D_Mw. This was done prior to the solve block to eliminate repeated computation of the diagonal matrix.
The multiplication operation below produces the desired result...a 5 x 1 vector. Note that the D_Mw matrix must pre-multiply the Rxn0 vector in order for the interior dimensions (in red) to match...(5 x 5) x (5 x 1).
In a similar manner, I needed to divide a vector by the molecular weights. The D_Mw matrix is a square diagonal matrix and thus it can be inverted.
Multiplying the vector by the ID_Mw matrix produces the desired "division".