MathGroup Archive 1993

[Date Index] [Thread Index] [Author Index]

Search the Archive

Mathematica Symbolic Toolbox for MATLAB

  • To: mathgroup at yoda.physics.unc.edu
  • Subject: Mathematica Symbolic Toolbox for MATLAB
  • From: doug
  • Date: Mon, 15 Nov 93 15:29:15 CST

(For information on how to obtain a copy of this free Toolbox, see the
section "Where to get the Mathematica Symbolic Toolbox for MATLAB" below)



Mathematica Symbolic Toolbox for MATLAB - Version 1.0 (15 November 1993)
------------------------------------------------------------------------
Using the MathLink communication standard supplied with Mathematica
and the MEX facility of MATLAB it was very easy to write a toolbox
that provides MATLAB users with all of the superior symbolic and
high-precision numeric capabilities of Mathematica. In addition,
since MathLink can pass native MATLAB matrices (and not just strings)
between Mathematica and MATLAB it is quick and easy to construct
matrices in either system and pass them to the other. You can freely
mix Mathematica code and MATLAB code without the bother of writing
M-files to convert matrices into strings and back. The Mathematica
Symbolic Toolbox for MATLAB is implemented as a single MEX-file
and we have included the source code.

Two important points:

1) The Mathematica Symbolic Toolbox for MATLAB works with all
   versions of Mathematica that support MathLink (including the
   Macintosh); no "special" version of Mathematica is required.
   Therefore, the Mathematica Symbolic Toolbox for MATLAB will work
   not only the with current version of Mathematica but also future
   versions as soon as they ship. As of today, (15 November 1993)
   MathLink-capable versions of Mathematica are shipping on Macintosh,
   NEXTSTEP, Unix, and VAX VMS machines; MathLink-capable versions
   of Mathematica for Microsoft Windows 3.1 and Windows NT will
   ship soon.
   
2) Since MathLink connects programs on different computers just as
   easily as it connects programs on the same computer, you can
   harness the power of more than one computer for your tough
   problems. Simply run MATLAB on one computer, Mathematica on
   another; the Mathematica Symbolic Toolbox for MATLAB transparently
   connects the two. This capability is also especially helpful in
   schools and industrial sites where MATLAB and Mathematica might
   be licensed for different machines.
   
Functions provided in the Mathematica Symbolic Toolbox for MATLAB
-----------------------------------------------------------------

math('string')      : 'string' is sent to Mathematica and evaluated; the
                    : result is returned as a string.
                    :
                    : <Optional for Macintosh users>
                    : Mathematica will automatically be started if you
                    : make an alias of the "Mathematica Kernel" icon, call
                    : the alias "MathKernel", and place the alias in the
                    : same folder as MATLAB itself. If you don't make the
                    : alias, the MathLink library will pose a dialog box
                    : and ask you to find a Mathematica Kernel.

math('matlab2math', 'mname', mat)    : The MATLAB matrix mat is assigned
                                     : to the Mathematica symbol denoted
                                     : by the string 'mname'. The result
                                     : returned to MATLAB is 'mname'.

math('math2matlab', 'expr')    : The matrix resulting from the evaluation
                               : of 'expr' by Mathematica is returned. If
                               : 'expr' doesn't yield a matrix, this function
                               : returns a MATLAB string containing '$Failed'

math('quit') or math('exit')   : These close the link and shut down Mathematica.
                               : You must call these manually when using
                               : MATLAB 3.5 since MEX functions don't get
                               : a "goodbye kiss" informing them to clean up.
                               : MATLAB 4.0 does provide this facility, so
                               : Mathematica will automatically shut down
                               : when you quit MATLAB.

All of the above automatically open a MathLink connection with
default arguments if one hasn't already been opened. If the user
wishes to open the connection with particular arguments, the full
form of the linkopen command is:

math('linkopen', 'linkname', 'linkmode', 'linkprotocol', 'swapEOL')
        : The first argument must be the string 'linkopen'.
        : The second argument must be the name of the link
        :    defined as usual for Mathematica's LinkOpen or the MathLink
        :    library's MLOpen(). Again, for simplicity, math('linkopen') uses
        :    the default arguments. LinkOpen and MLOpen() are described
        :    in the MathLink Reference Guide that ships with Mathematica.
        : The third argument is either 'Launch', 'Connect', or 'Listen'.
        : The fourth argument is either 'PPC' or 'TCP' on Macintosh,
        :    'Local' or 'TCP' on Windows, and 'Pipes' or 'TCP' on Unix.
        : If the fifth argument is 'swapEOL' then carriage-return and
        :    linefeed will be swapped; this is useful when connecting
        :    MATLAB and Mathematica processes residing on computers with
        :    different notions of end-of-line (for example, MATLAB on a Mac
        :    with Mathematica on a Sun SPARC). If the fifth argument is
        :    anything else, line termination will be unchanged.

In addition to the behavior above, any Mathematica warning or error
messages as well as the output from Mathematica's Print[] function
will appear in the MATLAB command window.

Here's an example of a session with MATLAB and Mathematica.

-----------------MATLAB Transcript Begins--------------
Hmath('$Version')
Mathematica Kernel loading...

ans =

Macintosh 2.2 (May 4, 1993)

Hmath('N[EulerGamma,40]')

ans =

0.5772156649015328606065120900824024310422

Hmath('matlab2math', 'hilbert',hilb(20))

ans =

hilbert

Hmath('{Dimensions[hilbert],Det[hilbert]}')

ans =

                      -188
{{20, 20}, -9.65397 10    }

Hmath('exactHilbert = Table[1/(i+j-1),{i,20},{j,20}];')

ans =

Null

Hmath('Det[exactHilbert]')

ans =

1 / 23774547167685345090916442434276164401754198377534864930331853312\
 
>    3441975931064458518758576681657377344056575986726555897176563841\
 
>    9710793303386582324149811241023554489166154717809635257797836800\
 
>    000000000000000000000000000000000

Hmath('N[Det[exactHilbert], 40]')

ans =

                                            -226
4.206178956624722655882045573396941339798 10

Hmath('invHilbert = Inverse[hilbert];')
Inverse::luc: Warning: Result for Inverse of badly conditioned matrix {<<20>>}
     may contain significant numerical errors.

ans =

Null

Hmath('math2matlab', 'invHilbert')

ans =

   1.0e+15 *

  Columns 1 through 7 

    0.0000   -0.0000    0.0000   -0.0000    0.0000   -0.0000    0.0000
   -0.0000    0.0000   -0.0000    0.0000   -0.0000    0.0000   -0.0000
    0.0000   -0.0000    0.0000   -0.0000    0.0001   -0.0004    0.0008
   -0.0000    0.0000   -0.0000    0.0002   -0.0013    0.0053   -0.0119
    0.0000   -0.0000    0.0001   -0.0013    0.0094   -0.0388    0.0903
   -0.0000    0.0000   -0.0004    0.0053   -0.0388    0.1630   -0.3911
    0.0000   -0.0000    0.0008   -0.0119    0.0903   -0.3911    0.9753
   -0.0000    0.0000   -0.0008    0.0127   -0.1009    0.4615   -1.2351
   -0.0000    0.0000   -0.0002    0.0026   -0.0110   -0.0001    0.1711
    0.0000   -0.0000    0.0014   -0.0206    0.1537   -0.6486    1.5388
   -0.0000    0.0000   -0.0009    0.0147   -0.1190    0.5546   -1.5043
   -0.0000    0.0000   -0.0004    0.0051   -0.0333    0.1139   -0.1624
    0.0000   -0.0000    0.0005   -0.0081    0.0630   -0.2725    0.6320
   -0.0000    0.0000   -0.0002    0.0029   -0.0166    0.0335    0.1010
    0.0000   -0.0000    0.0004   -0.0050    0.0298   -0.0764   -0.0255
   -0.0000    0.0000   -0.0002    0.0033   -0.0251    0.1057   -0.2268
    0.0000   -0.0000    0.0000    0.0000   -0.0024    0.0309   -0.2063
   -0.0000    0.0000   -0.0004    0.0042   -0.0193    0.0007    0.3677
    0.0000   -0.0000    0.0005   -0.0058    0.0334   -0.0757   -0.1028
   -0.0000    0.0000   -0.0002    0.0020   -0.0121    0.0345   -0.0106

  Columns 8 through 14 

   -0.0000   -0.0000    0.0000   -0.0000   -0.0000    0.0000   -0.0000
    0.0000    0.0000   -0.0000    0.0000    0.0000   -0.0000    0.0000
   -0.0008   -0.0002    0.0014   -0.0009   -0.0004    0.0005   -0.0002
    0.0127    0.0026   -0.0206    0.0147    0.0051   -0.0081    0.0029
   -0.1009   -0.0110    0.1537   -0.1190   -0.0333    0.0630   -0.0166
    0.4615   -0.0001   -0.6486    0.5546    0.1139   -0.2725    0.0335
   -1.2351    0.1711    1.5387   -1.5043   -0.1624    0.6319    0.1010
    1.7638   -0.6488   -1.6905    2.1450   -0.1677   -0.4802   -0.7605
   -0.6488    1.0265   -0.4581   -0.6978    1.1006   -1.2186    1.8770
   -1.6905   -0.4581    3.1951   -2.1076   -2.0256    3.4976   -2.0840
    2.1450   -0.6978   -2.1076    1.8076    2.0058   -2.9802    0.5148
   -0.1677    1.1006   -2.0256    2.0058   -0.9561   -0.3424    0.3584
   -0.4802   -1.2186    3.4976   -2.9803   -0.3424    1.1653    1.5170
   -0.7604    1.8770   -2.0840    0.5148    0.3584    1.5170   -2.2628
    0.6600   -1.6664    1.8583   -1.1600    1.3985   -1.6074   -1.2829
    0.0588    1.0016   -2.8111    3.6027   -1.5934   -2.1674    4.1533
    0.8399   -2.1368    3.1884   -1.9160   -1.8231    4.1361   -2.2408
   -1.6436    3.3166   -2.7454   -1.2657    4.3571   -2.5566   -0.6112
    0.9875   -2.1750    1.5248    1.4957   -2.9165    0.6818    0.9476
   -0.2012    0.5167   -0.3664   -0.3893    0.6816   -0.0597   -0.2464

  Columns 15 through 20 

    0.0000   -0.0000    0.0000   -0.0000    0.0000   -0.0000
   -0.0000    0.0000   -0.0000    0.0000   -0.0000    0.0000
    0.0004   -0.0002    0.0000   -0.0004    0.0005   -0.0002
   -0.0050    0.0033    0.0000    0.0042   -0.0058    0.0020
    0.0298   -0.0251   -0.0024   -0.0193    0.0334   -0.0121
   -0.0764    0.1057    0.0309    0.0007   -0.0757    0.0345
   -0.0255   -0.2268   -0.2063    0.3677   -0.1028   -0.0106
    0.6601    0.0588    0.8399   -1.6436    0.9875   -0.2013
   -1.6665    1.0017   -2.1368    3.3166   -2.1750    0.5167
    1.8583   -2.8112    3.1885   -2.7454    1.5248   -0.3664
   -1.1600    3.6028   -1.9160   -1.2658    1.4958   -0.3893
    1.3985   -1.5933   -1.8231    4.3572   -2.9165    0.6816
   -1.6074   -2.1675    4.1361   -2.5566    0.6818   -0.0597
   -1.2829    4.1534   -2.2408   -0.6112    0.9476   -0.2464
    4.2719   -2.5180   -0.7444    1.0501   -0.0983   -0.0847
   -2.5180   -0.3671    1.2869   -0.4704   -0.1025    0.0697
   -0.7444    1.2869   -0.6004    0.4417   -0.3602    0.1064
    1.0500   -0.4704    0.4417   -0.1468   -0.1696    0.0909
   -0.0982   -0.1025   -0.3602   -0.1696    0.5406   -0.2056
   -0.0847    0.0697    0.1064    0.0909   -0.2056    0.0744

Hmath('quit')
Mathematica Kernel quitting per your request...
H
-----------------MATLAB Transcript Ends--------------

Where to get the Mathematica Symbolic Toolbox for MATLAB
--------------------------------------------------------
(1) anonymous ftp to mathsource.wri.com;
        look in /pub/WhatsNew for the file matlab2math.sea.hqx (Macintosh)
        or matlab2math.tar.Z (Unix).
        A .zip will appear when the MathLink-capable version of
        Mathematica for Windows ships.

(2) send the email "send 0205-951" to mathsource at wri.com

(3) coming soon to Internet sites and mailing lists near you


What's included in this archive
-------------------------------

README - this file
math35.c - source code suitable for MATLAB 3.5's MEX facility
math40.c - source code suitable for MATLAB 4.x's MEX facility
math.make - a makefile suitable for the Apple MPW development system
math.mex.sea.hqx - a Binhexed, self-unstuffing archive containing the
        compiled Macintosh version for MATLAB 3.5.


How to build the Mathematica Symbolic Toolbox for MATLAB
--------------------------------------------------------
First of all, you need access to a licensed copy of Mathematica.
The standard Mathematica distribution includes the MathLink header
and library files.

Macintosh:
----------
1) Make sure you've installed the MathLink libraries for MPW that
   come with your copy of Mathematica.
   
2) Open math.make and change the values for the constants MexDir
   and MexLibDir if necessary.
   
3) Rename math35.c or math40.c to math.c depending on which version
   of MATLAB you wish to build for.
   
4) Execute the following in MPW:
   make math.mex -f math.make
   
   
Unix:
-----
1) Find out where libML.a and mathlink.h are installed on your system.

2) Assuming you've properly installed the MEX tools for MATLAB, type:
   cmex -O -Iinclude_path -Llibrary_path -lML math35.c -o math.mex
   or
   cmex -O -Iinclude_path -Llibrary_path -lML math40.c -o math.mex
   (where include_path is the location of mathlink.h and library_path
    is the location of libML.a)

Windows:
--------
More detailed instructions will follow when MathLink for Windows
ships.  MathLink is shipped as a Windows DLL, so you can use
Microsoft, Borland, or Symantec compilers. Each is different in
its usage.

Questions ?
-----------

1) If you don't already have access to a copy of Mathematica, just contact
   Wolfram Research, Inc. at:

   Phone: 1-800-441-MATH
   FAX:   1-217-398-0747
   EMail: info at wri.com

2) If you're curious about MathLink or have suggestions about how to make this
   free Mathematica Symbolic Toolbox for MATLAB better, send email to:

   mathlink at wri.com


Cordially,

Doug Stein
MathLink Development Group
Wolfram Research, Inc.






  • Prev by Date: Integrate Bug...
  • Next by Date: Missing underscores
  • Previous by thread: Integrate Bug...
  • Next by thread: Missing underscores