MC++
|
mc::FFDep is a C++ class that determines the structure of mathematical expressions, namely their sparsity pattern and linearity, for a given set of participating variables. It relies on the operator overloading and function overloading mechanisms of C++. The overloaded operators are: `+', `-', `*', and `/'; the overloaded functions are: `exp', `log', `sqr', `pow', `sqrt', `fabs', `xlog', `min', `max', `cos', `sin', `tan', `acos', `asin' and `atan'.
Suppose you are given 4 variables \(x_1,\ldots,x_4\) and want to determine the sparsity pattern and linearity of the vector following function
\begin{eqnarray*} {\bf f}({\bf x}) = \left(\begin{array}{c} f_1({\bf x})\\ f_2({\bf x})\end{array}\right) = \left(\begin{array}{c} x_3 x_4+x_1\\x_1(\exp(x_3-x_4))^2+x_2 \end{array}\right) \end{eqnarray*}
First, define the variables \(x_1,\ldots,x_4\) as
Essentially, the first line means that X
is an array of mc::FFDep class objects, and the second line defines X[0],...X[NX-1] as independent variables with indices 0,...,NX-1, respectively.
Once the independent variables \({\bf x}\) have been defined, determine the structure of \({\bf f}({\bf x})\) simply as
Retrieve the structure - both the sparsity pattern and the linearity - of \(f_1\) and \(f_2\) as
You can also display the structure as
The corresponding output is
Variable dependence of F[0]: { 0L 2NL 3NL } Variable dependence of F[1]: { 0NL 1L 2NL 3NL }
which indicates that X[0], X[2] and X[3] participate in F[0], but not X[1]. Moreover, X[0] participates linearly, unlike X[2] and X[3].
Errors are managed based on the exception handling mechanism of the C++ language. Each time an error is encountered, a class object of type FFDep::Exceptions is thrown, which contains the type of error. It is the user's responsibility to test whether an exception was thrown during a calculation, and then make the appropriate changes. Should an exception be thrown and not caught by the calling program, the execution will stop.
Possible errors encountered in determining the structure of a factorable function are:
Number | Description |
---|---|
-33 | Error due to calling a feature not yet implemented in mc::FFDep |