File Exchange

image thumbnail

Mathematica Symbolic Toolbox for MATLAB--Version 2.0

version 1.2 (43.1 KB) by

A symbolic toolbox for MATLAB based on Mathematica.

69 Downloads

Updated

View License

A symbolic toolbox that provides MATLAB users with all of the symbolic and high-precision numeric capabilities of Mathematica. It uses the MathLink communication standard supplied with Mathematica and the MEX facility of MATLAB. 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. One 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 the source code is included. Precompiled linux and windows executables are included. Installation instructions for MACs are included in the README.Version 2.0 has been updated from:http://library.wolfram.com/infocenter/MathSource/624 to work with MATLAB R2007b and Mathematica 6.0.

Comments and Ratings (36)

yi huo

yi huo (view profile)

I wanna use the matlab R2016b link to mathematica 9.0.1, when I run the mathrun.m, it doesn't work and show the messages as the following information: I want help, any answers it ok, ANY LUCK ONE CAN HELP ME?

使用 'MinGW64 Compiler (C)' 编译。
<command-line>:0:0: warning: "__STDC__" redefined
<built-in>: note: this is the location of the previous definition
C:\mathematica_for_matlab\math.c: In function 'MathLinkStringEval':
C:\mathematica_for_matlab\math.c:306:59: warning: passing argument 3 of 'MLGetByteString' from incompatible pointer type [-Wincompatible-pointer-types]
     MLGetByteString(mlp, (const unsigned char **)&outStr, &len, '\0');
                    ^
In file included from C:\mathematica_for_matlab\math.c:36:0:
C:\mathematica_for_matlab/mathlink.h:4024:16: note: expected 'int *' but argument is of type 'long int *'
 MLDECL( int, MLGetByteString, ( MLINK mlp, const unsigned char **sp, int *lenp, long missing));
                ^
C:\mathematica_for_matlab/mathlink.h:640:58: note: in definition of macro 'MLDECL'
 # define MLDECL( rtype, name, params) extern rtype MLAPI name P(params)
                    ^
C:\mathematica_for_matlab\math.c: In function 'WaitForReturnPacket':
C:\mathematica_for_matlab\math.c:540:61: warning: passing argument 3 of 'MLGetByteString' from incompatible pointer type [-Wincompatible-pointer-types]
       MLGetByteString(mlp, (const unsigned char **)&msgStr, &msglen, '\0');
                    ^
In file included from C:\mathematica_for_matlab\math.c:36:0:
C:\mathematica_for_matlab/mathlink.h:4024:16: note: expected 'int *' but argument is of type 'long int *'
 MLDECL( int, MLGetByteString, ( MLINK mlp, const unsigned char **sp, int *lenp, long missing));
                ^
C:\mathematica_for_matlab/mathlink.h:640:58: note: in definition of macro 'MLDECL'
 # define MLDECL( rtype, name, params) extern rtype MLAPI name P(params)
                    ^

<command-line>:0:0: warning: "__STDC__" redefined
<built-in>: note: this is the location of the previous definition

错误使用 mex
C:\mathematica_for_matlab\ml64i3m.lib: error adding symbols: File format not recognized
collect2.exe: error: ld returned 1 exit status

出错 mathrun (line 9)
eval(command)

ctaoist cta

I compile the mex file on Mac OS X 10.12 for Mathematica 11.0.1 and MATLAB 2014b by using the command:
mex -I/Applications/Mathematica.app/Contents/SystemFiles/Links/MathLink/DeveloperKit/MacOSX-x86-64/CompilerAdditions -L/Applications/Mathematica.app/Contents/SystemFiles/Links/MathLink/DeveloperKit/MacOSX-x86-64/CompilerAdditions -lMLi4 math.c

I have edited the math.c line 227 as suggested in the comments below it.
But I get such error:
Undefined symbols for architecture x86_64:
  "_CFDictionaryCreate", referenced from:
      _MLAlert_darwin in libMLi4.a(mlosx.c.o)
      _MLRequest_darwin in libMLi4.a(mlosx.c.o)
      _MLConfirm_darwin in libMLi4.a(mlosx.c.o)
  "_CFRelease", referenced from:
      _MLAlert_darwin in libMLi4.a(mlosx.c.o)
      _MLRequest_darwin in libMLi4.a(mlosx.c.o)
      _MLConfirm_darwin in libMLi4.a(mlosx.c.o)
  "_CFStringCreateWithCString", referenced from:
      _MLAlert_darwin in libMLi4.a(mlosx.c.o)
…………………………………………
"_kCFUserNotificationTextFieldValuesKey", referenced from:
      _MLRequest_darwin in libMLi4.a(mlosx.c.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Any advice?

Matt

Matt (view profile)

I managed to successfully compile the MEX file using Brenno's instructions. However, when I run the test script I get the following error:

Invalid MEX-file 'C:\XXX\math.mexw64': Invalid access to memory location.

Error in testscript (line 1)
math('quit')

Brenno

Brenno (view profile)

I have found the solution for the issues that both me and "varan gupta" were having:

Make sure to include the module "ml64i3.dll" next to the compiled "math.mexw64" file, I found the module at:

"C:\Program Files\Wolfram Research\Mathematica\10.4\SystemFiles\Links\MathLink\DeveloperKit\Windows-x86-64\SystemAdditions"

I just searched "ml64i3.dll" in the mathematica program directory to find the little sucker.

as long as the "math.mexw64" and "ml64i3.dll" files are in a directory within Matlab's search path you are good to go!

Brenno

Brenno (view profile)

I am using Windows 7, MatlabR2015b, Mathematica 10.4 and having the same issue as "varan gupta".

Attempted to use Visual Studio Express 2013 without much luck on "mex -setup" to recognize it. Finally switched to "Visual Studio 2012 Pro which is free online and got the sucker to compile using the "ml4i3m.lib" as mentioned before.

Any luck anyone?

varan gupta

I am using matlab2016a 64 bit.
i am getting error:
Invalid MEX-file 'e:\mathematica_matlab\math.mexw64': The specified module could not be found.

Justine

Firstly, thank you this is extremely helpful!

However, it took me 3 days to get this to work, so I thought I'd share what worked for me (Mathematica 10.0, Matlab R2014b, Ubuntu 14.04):

When setting up mex, make sure to change all instances of 'gcc' to 'gcc-4.7' and change 'g++' to 'g++-4.7' in mexopts.sh

include_path = library_path = /usr/local/Wolfram/Mathematica/10.0/SystemFiles/Links/MathLink/DeveloperKit/Linux-x86-64/CompilerAdditions/

The readme file's "libML.a" is "libML64i3.a" for me, so I needed to type:
mex -Iinclude_path -Llibrary_path -lML64i3 math.c

For point 3), I just added the whole folder by adding the following to my startup.m file (not sure how bad that is):
addpath(genpath('/usr/local/Wolfram/Mathematica/10.0/Executables/'));

Even after exporting the LD_LIBRARY_PATH the shared libraries were not being found. After much time spent with nothing helping, doing the following worked:

create a file in /etc/ld.so.conf.d called, say, mathematica.conf containing library_path, i.e. for me the line:
/usr/local/Wolfram/Mathematica10.0/SystemFiles/Links/MathLink/DeveloperKit/Linux-x86-64/CompilerAdditions

save the file and then type:
/sbin/ldconfig

If you then type the command:
/sbin/ldconfig -p | grep libML64i3.so

its presence should be shown along with the path to it

I hope that saves someone some of the time I lost!

Lars

Lars (view profile)

Successfully compiled under Windows7 x86-64 with MATLAB R2014b and Mathematica 10.0.0.0 using the default math.c (not the one from 'math_windows.zip') and ml64i3m.lib instead of ml32i1m.lib.
Compiler: Microsoft Visual C++ 2010 (C)

The compiled file 'math.mexw64' seems to work mostly fine on my machine (quick test with the examples from the README - only thing that didn't work was the command 'diag(hilbert)')

ep

ep (view profile)

Does this work with Mathematica 9 and MATLAB R2014a?

karlosgk

karlosgk (view profile)

Fra85

Fra85 (view profile)

Hi,

I get quite a few compiling errors when producing the mex file. I am using Microsoft Visual C++ 2010 Express and MATLAB Version 7.11.0.584 (R2010b). After adding folders to path, I get:

LINK : warning LNK4044: unrecognized option '/lkernel32'; ignored
   Creating library C:\Users\FRANCE~1\AppData\Local\Temp\mex_v3XQyS\templib.x and object C:\Users\FRANCE~1\AppData\Local\Temp\mex_v3XQyS\templib.exp
math.obj : error LNK2019: unresolved external symbol MLClose referenced in function CloseMathLink
math.obj : error LNK2019: unresolved external symbol MLNewPacket referenced in function WaitForReturnPacket
math.obj : error LNK2019: unresolved external symbol MLDisownString referenced in function WaitForReturnPacket
math.obj : error LNK2019: unresolved external symbol MLGetByteString referenced in function WaitForReturnPacket
math.obj : error LNK2019: unresolved external symbol MLNextPacket referenced in function WaitForReturnPacket
math.obj : error LNK2019: unresolved external symbol MLClearError referenced in function HandleMathLinkError
math.obj : error LNK2019: unresolved external symbol MLErrorMessage referenced in function HandleMathLinkError
math.obj : error LNK2019: unresolved external symbol MLEndPacket referenced in function OpenMathLink
math.obj : error LNK2019: unresolved external symbol MLPutString referenced in function OpenMathLink
math.obj : error LNK2019: unresolved external symbol MLPutFunction referenced in function OpenMathLink
math.obj : error LNK2019: unresolved external symbol MLOpen referenced in function OpenMathLink
math.obj : error LNK2019: unresolved external symbol MLPutDoubleArray referenced in function PutArrayToMathematica
math.obj : error LNK2019: unresolved external symbol MLPutSymbol referenced in function PutArrayToMathematica
math.obj : error LNK2019: unresolved external symbol MLDisownDoubleArray referenced in function GetArrayFromMathematica
math.obj : error LNK2019: unresolved external symbol MLGetDoubleArray referenced in function GetArrayFromMathematica
math.obj : error LNK2019: unresolved external symbol MLCheckFunction referenced in function GetArrayFromMathematica
math.obj : error LNK2019: unresolved external symbol MLGetType referenced in function GetArrayFromMathematica
math.mexw64 : fatal error LNK1120: 17 unresolved externals
 
  C:\PROGRA~1\MATLAB\R2010B\BIN\MEX.PL: Error: Link of 'math.mexw64' failed.

Thank you for your help.

Francesco

Jessica

I've used this for a few years and find it works very well. I'm trying now to compile it on a Mac running OS 10.7.5

I'm using the command

mex -I/usr/include/ -lMLi3 math.c

and get

if: Expression Syntax.
ld: library not found for -lMLi3
collect2: ld returned 1 exit status

    mex: link of ' "math.mexmaci64"' failed.

The library file is definitely in the directory I'm specifying. I see a note in the README that the library path needs to be on the (DY)LD_LIBRARY_PATH - could this be the problem? Any advice would be appreciated

Anh Nguyen

I have the same problem when trying to install the packet. I am using Matlab2011b (64bit), Mathematica, 8.0 Windows 7. When I run "mex - setup" from Matlab, it shows

C:\PROGRA~1\MATLAB\2011B\BIN\MEX.PL: Error: '–setup' not found.
 
Error using mex (line 206)
Unable to complete successfully.

I appreciate very much if anyone can help.

jure

jure (view profile)

i forgot to tell; I have Mathematica 8, MATLAB R2011b and Windows Vista

jure

jure (view profile)

I have troubles with installing this toolbox. After choosing Microsoft Visual C/C++, Mex-setup gives me an error:
mex-setup
    Usage:
        MEX [option1 ... optionN] sourcefile1 [... sourcefileN]
            [objectfile1 ... objectfileN] [libraryfile1 ... libraryfileN]
 
    Use the -help option for more information, or consult the MATLAB API Guide.
 
 
  C:\PROGRA~1\MATLAB\R2011B\BIN\MEX.PL: Error: No file names given.
 
Undefined function or variable 'setup'.

I have no idea what I'm doing wrong, so if anyone can help me I'll be really grateful. Thanks.
 

In newer OS X Version you have to add the additional flag
  "-framework Foundation"
to CLIBS in mexopts.sh

Ross Anderson

how i download toolbox thanks in advance

Huang Meng

I wonder how to pass the symbolic in matlab to mathematica and return the result to matlab

Matthias

Hello,
I liked this toolbox very much. I used it successfully with Matlab R2010a and Mathematica 7.0. But now it won't start anymore. I get following error:
"MathLink connection unexpectedly NULL!"
I additionally installed Mathematica 8.0. Is this problem or is it because of some windows updates?

An excellent contribution. Stable and reliable. Thank you Ben.

Denis Rosset

Excellent package, thank you !

This works under x64 environment;
 Mathematica 7.0 win64, MATLAB win64 7.10, Visual Studio 2008, Vista x64.
You have to use mldev64\include and lib\ml64i3m.lib instead of 32bits one.

Be careful not to use Visual Studio Express edition.
I failed to compile mex at first, as they have no x64 libs.
Thx.

Dmitry Savransky

As usual from this author, a great addition to MATLAB. Quick note for those compiling on OS X - make sure you edit math.c line 227 as suggested in the comments below it, but don't worry about setting the library path. Your mex line should be something like:
mex -I/Applications/Mathematica.app/SystemFiles/Links/MathLink/DeveloperKit/CompilerAdditions/ -L/Applications/Mathematica.app/SystemFiles/Links/MathLink/DeveloperKit/CompilerAdditions/ -lMLi3 math.c

Tested with MATLAB 2009b and Mathematica 7 on Win Vista. Seems to work fine!

Ahmad Chkeir

hello guys.
I just installed Matlab 2009a but it dosen't include symbolic toolbox. I downloaded this file "Mathematica Symbolic Toolbox for MATLAB--Version 2.0" but I didn't know what to do later. how can
i add the symbolic tool to my matlab ?

Hi,
I downloaded this package but got a segmentation violation when running the supplied precompiled math.dll. I am using Matlab 2008a and Mathematica 6.0. Then I copied the mathlink.h and the ml32i1m.lib from the Mathematica directory and tried compiling math.c. However, when I run the mathrun.m script on Matlab I get this error:

C:\PROGRA~1\MATLAB\R2008A\BIN\MEX.PL: Error: 'and' not found.
 
??? Error using ==> mex at 207
Unable to complete successfully.

Any help?
Thanks a lot.
Gonçalo

Error in ==> mathrun at 8
eval(command)

Martin

Martin (view profile)

I try to install it on Mac OS 10.4.
I cannot compile math.c with mex, i get a parse error the following error:

In file included from math.c:35:
/Applications/Mathematica 5.2.app/AddOns/MathLink/DeveloperKit/Darwin/CompilerAdditions/mathlink.h:92: error: parse error before 'yet'
/Applications/Mathematica 5.2.app/AddOns/MathLink/DeveloperKit/Darwin/CompilerAdditions/mathlink.h:408: error: syntax error before 'enum'
math.c: In function 'MathLinkStringEval':
math.c:332: warning: passing argument 3 of 'MLGetByteString' from incompatible pointer type
math.c: In function 'WaitForReturnPacket':
math.c:566: warning: passing argument 3 of 'MLGetByteString' from incompatible pointer type

Can anybody help me?
Thanks

a s

In case anyone gets here b/c they're having the same problem I was, I figured out how to fix the problem.

The issue is that when you do: -lML the compiler looks for a library named libML.a. However, on my machine the library is named libMLi3.a.

Therefore if I run:
/Applications/MATLAB74/bin/mex -I/Applications/Mathematica.app/SystemFiles/Links/MathLink/DeveloperKit/CompilerAdditions/ -L/Applications/Mathematica.app/SystemFiles/Links/MathLink/DeveloperKit/CompilerAdditions/ -lMLi3 math.c

Then everything works out hunky dory.

Thanks,
AS

a s

I can't get this to compile on my Mac (OS 10.5.5).

I changed the math.c file as instructed in the readme. When i compile I get an error:
$ /Applications/MATLAB74/bin/mex -I/Applications/Mathematica.app/SystemFiles/Links/MathLink/DeveloperKit/CompilerAdditions/ -L/Applications/Mathematica.app/SystemFiles/Links/MathLink/DeveloperKit/CompilerAdditions/ -lML math.c
ld: library not found for -lML
collect2: ld returned 1 exit status

    mex: link of 'math.mexmac' failed.

----
Anyone have any suggestions as to why that is not working?

Thanks,
AS

shisen du

optical laser

arash paivar

dear ben do you know why i recieved incorrect result by this:
k=sym('k','positive');
z1=1.21+0.008*i
k1=((z1-k))^(1/2);

t=2*pi*k/(imag(k1))
s=int(t,k);

John Szumiloski

Not thoroughly tested, but so far appears to do just what the help files say. This is an invaluable tool to supplement the numeric and application-specific capabilities of MATLAB with the symbolic and programming (Map[], Apply[], etc.)strengths of Mathematica. Just what I needed. Fantastic! (Note: MathSource link is not right as of 2006-05-31. should be space between final '624/' and 'to'.)

Indrid Cold

Wow! Appreciate this a lot.

Matt W.

Awesome! you saved me from coding MathieuC, thank you

Walid Maghroum

Hi,
Thank you for updating the archive to work with matlab 7.0.
Could you please check the .tar archive?The I could not open the archive because it seems to be corrupted.
thanks a lot
Walid

Updates

1.2

Removed mex file

1.1

updated to work with mathematica 7

Doc update. New binary. Recompiled to work with most recent versions.

Documentation link fix.

better windows support

better windows support

Better packaging.

Updated with MAC installation instructions.

updated help for windows users

Now including windows dll. Updated description.

Title should be 2.0, slightly updated mex file and README file.

MATLAB Release
MATLAB 7 (R14)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

mathematica_for_matlab/