Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.
|
|
|
|
'Open' languages: e.g., MATLAB
Posted:
Jun 29, 1996 12:20 PM
|
|
I've recently had occasion to use 'MATLAB' (tm The Math Works, Inc.), which is a little language that gives access to some linear algebra and other numerical analysis routines. Apparently, it is used in undergraduate university courses in linear algebra, numerical analysis, linear systems theory and signal processing, and perhaps some statistical analysis courses.
Although the MATLAB language leaves a _lot_ to be desired in terms of its elegance and clarity -- especially when compared with some of its competitors -- e.g., APL -- it does have some interesting features which make it easier to use.
(I haven't studied the MATLAB language thoroughly, nor do I know any of the details of how it is implemented, so some of the items below are educated guessing on my part.)
1. There seems to be a 1-1 relationship between functions and files. While this leads to extremely small files, it also allows for the file system itself to be part of the language 'name space'. Apparently, when MATLAB is started up, it searches the appropriate directories and _automagically_ builds the appropriate 'autoload' capabilities, so that when a function is referenced, it knows where to find it.
For those who have had to keep 'autoload' properties in Lisp systems consistent with the locations of files, this greatly reduces that work.
This function=file relationship gives MATLAB more of a feeling of a Unix 'shell' language, because the programmer does not have to go to any trouble keeping the file system and the internal name space consistent.
MATLAB itself seems to go to a lot of trouble to keep the file & the function consistent. Although MATLAB provides its own function editor, one is also allowed to use another editor -- e.g., Emacs -- and MATLAB apparently notices when one of its files gets updated.
2. MATLAB provides a 'named' scheme for multiple returned values. If a function produces multiple values -- e.g., the singular value decomposition for matrices, which produces U, S, V, where U,V are unitary/orthogonal matrices, and S is a diagonal matrix -- then one defines the function like so:
function [U,S,V] = svd(M)
and then references U,S,V by name within the function. This is almost a return to the yesteryear of Fortran 1, where one assigned the function name itself with a value to be returned.
Those in the prolog/logic community will find this old hat. Those from the Pascal/Ada community will probably be confused, since it appears that the returned values are all constructed within the function and passed out; these apparently are _not_ 'var'/'inout' parameters.
I'm not sure how this is implemented in MATLAB. In particular, I'm not completely sure what happens when a multi-valued function is used 'functionally' -- I think that perhaps only the first value is then used.
(This is one of the big problems with MATLAB -- the documentation is woefully inadequate at explaining the intricacies of name binding, semantics of parameter passing and value returning, etc. For a language that is aimed somewhat at _mathematicians_, such ambiguities and sloppiness are unforgiveable.)
3. MATLAB does go to substantial effort to try to get the 'right' semantics for 'NaN's' ("Not-a-Numbers"). It may be the first language since the Lisp Machines that really put in an effort to do this right.
4. MATLAB shows that if the underlying subroutines are high quality, people will put up with a lot of inelegancies in the 'scripting' language. Some would say that the graphing/plotting capabilities alone are worth the price of admission.
-------
On the negative side, MATLAB's integration with the Maple symbolic algebra package is a bad joke. Although the Maple system itself is actually quite good, one would have a difficult time coming to that conclusion after trying to use Maple within MATLAB. Apparently, the only communication between MATLAB and Maple is in the form of character strings, so there's a _lot_ of parsing and unparsing going on!
Also, Maple uses an entirely different set of names for operations than does MATLAB -- e.g., MATLAB uses the single quote "'" for the transpose (conjugated), while Maple uses the 'transpose()' function.
MATLAB understands complex numbers very well, but Maple (at least as incorporated into MATLAB) doesn't seem to understand complex numbers at all.
--------
In summary, MATLAB is a useful tool because of its high quality library of built-in functions and graphing/plotting capabilities, and because it allows a relatively simple programming model which hides many of the problems of the internal v. file-system issues.
It is a shame, however, that 'scripting languages' like MATLAB didn't learn a bit more from languages like APL in the areas of generalized arrays and array-indexing, and from languages like Lisp/etc. in the areas of data structures more sophisticated than arrays for symbolic algebra.
I'm somewhat concerned that non-CS undergraduate students will come to the conclusion that MATLAB is 'state of the art' in terms of computer language design, and that misconception would be a real shame. Perhaps the company could at least include a disclaimer regarding the MATLAB/Maple interface, and tell the students that they realize that it is kludgey, and that they will attempt to improve this in the future.
-- www/ftp directory: ftp://ftp.netcom.com/pub/hb/hbaker/home.html
|
|
|
|