Using the C++ Math Library | ![]() ![]() |
Introduction
The mwArray
class public interface (those functions you can call directly) is relatively small, consisting of constructors and a destructor, overloaded new
and delete
operators, one user-defined conversion, indexing operators and functions, the assignment operator, input and output operators, and array size query routines. Since the mwArray
public interface is relatively small, it is not likely to require extensive modification in future versions of the library.
The mwArray
's public interface does not contain any mathematical operators or functions. This does not mean, of course, that these operators and functions are not available. To the contrary, the MATLAB C++ Math Library contains more than 400 mathematical routines. These routines use the mwArray
class interface; however, they are not member functions.
Both the users of a library and its developers benefit from a relatively small, static interface for the mwArray
class. The smaller interface is easier to understand than a larger one simply because it contains fewer routines. Similarly, the uniform interface for the mathematical functions, in which the rules are the same for all functions, is easier to learn. By virtue of being excluded from the interface of the mwArray
class, the mathematical routines gain a uniformity of interface.
For example, consider the functions transpose()
and eig()
. An argument could be made that transpose()
should be a member function of mwArray
, for then it would be invoked by the syntax A.transpose()
, which is quite natural to both mathematicians and C++ programmers. However, the case for eig()
as a member function is much weaker. eig()
can be called with several different types of arguments. In at least one of the combinations,[V, D] = eig(A, B)
, it is not clear which, if any, of the arguments is the ``object'' on which eig()
is invoked. Furthermore, because of the way in which multiple return arguments are implemented in the MATLAB C++ Math Library, picking an arbitrary input argument to act as the ``object'' produces a confusing interleaving of input and output arguments.
This problem arises with many functions in the MATLAB C++ Math Library, making them inappropriate mwArray
member functions. Rather than divide the mathematical routines into two groups - member functions and nonmember functions - we decided that a uniform interface to the mathematical functions was more important than dogmatically adhering to the object.function()
syntax of C++. Therefore, none of the MATLAB mathematical routines are member functions of mwArray
.
![]() | The C++ roots() Function | Constructors | ![]() |