# Tag Info

53

2014-04-12 NOTICE: MATLAB R2014a contains a bug that breaks MATLink on OS X and Linux (Windows is fine). If you use MATLink on OS X or Linux, please consider keeping MATLAB R2013b until R2014b comes out. Due to the nature of the problem there is no quick workaround that we could apply in MATLink. For full compatibility with Mathematica 10, please upgrade ...

46

Here is my pitch to use LibraryLink, which is a really nice new technology in version 8. I am not going to pretend this is easy by any stretch of the imagination, because it involves a decent amount of knowledge of both Mathematica and C compilers. In this particular case I am using Visual Studio C++ Express plus the Microsoft Windows SDK 7.1. For the record,...

36

On Windows, C/C++ functions that have been compiled into DLLs can be accessed reasonably easily using NETLink. Let's say we have the following C++ DLL definition: #include "stdafx.h" BOOL APIENTRY DllMain(HMODULE module, DWORD reason, LPVOID reserved) { return TRUE; } extern "C" __declspec(dllexport) void helloMma(double a, double b, int n, double m[]...

33

Here is a package which I think does what you want: https://www.wolframcloud.com/objects/user-7053ce31-817f-4643-aec1-eda27051bba6/WebUnit.zip Download the file, and unzip it, and place the WebUnit folder under $UserBaseDirectory/Applications To use it: Needs["WebUnit"] InstallWebUnit[] (* launches chromedriver.exe *) StartWebSession[] (* launches ... 28 This is a good application for the highly underused Splice function which has been in Mathematica since version 1 (I don't recall it ever being used on this site). Create a file called main.mtex with the following text: \documentclass[preview,border=12pt,12pt]{standalone} \usepackage{amsmath} \def\f(#1){(#1)^2-5*(#1)+6} \begin{document} \section{... 27 Presuming that your c++ code is already written, then I don't know how the code generation feature would be helpful. That said, in order of simplicity, I would have Get, ReadList, Import, and both LibraryLink and MathLink. Get and ReadList are by far the simplest. Provided that your c++ program outputs to stdout (std::cout), then it is simply val = (&... 26 Your problem is that you've got a slight misunderstanding of the different types of items that ReadList can read. That's OK, it can be a little confusing. To begin with: String, Number, Expression, etc. are not sub-types of Record. They are all separate types with their own rules for how they are read. The RecordSeparators option is only applied to ... 25 Here are three very simple examples to show how to call a Fortran subroutine using LibraryLink. First the subroutine is compiled into object file. Then a wrapper is used to call the Fortran subroutine and compiled into dynamic library. At the end, the library is loaded into Mathematica and run. In the examples Mathematica Version 8 is used. FIRST EXAMPLE ... 24 IronPython requires .NET 4.0 to run. As of V8, Mathematica launches .NET 2.x by default. See this question for details about how to use .NET 4.0. Having done that, we need to load the IronPython assembly into the .NET framework: Needs["NETLink"] InstallNET[];$pythonDll = "C:\\Program Files (x86)\\IronPython 2.7.1\\IronPython.dll"; LoadNETAssembly[$... 23 I wrote a small package for this. The main reason why I'm posting it here is to get some feedback on how to improve it. I'm new both R and RLink. You can get the package here. Please see the installation instructions in README.md, especially if you're a Mac user (important!). How does it work? RLink does not play well with igraph objects, so an edge-... 22 The solution is forcing .NET/Link to load its 32-bit executable instead of the 64-bit one. Since Mathematica communicated with the .NET/Link process through MathLink, it does not matter if the Mathematica kernel is 64 bit and the .NET/Link executable is a 32 bit version. They are separate processes. However, the .NET/Link executable must match the DLL ... 22 I suggest to use MathLink, which you can automate using the CCompilerDriver. This is a safe alternative, since you won't crash the kernel if your code crashes. Once tested, this should not be hard to convert to library link. As an explicit example, consider a function which receives a list of integers and squares it. First, here is a function to create the ... 21 On Windows 7 using ReadList instead of Run suppresses the window: Table[Pause[1/2]; ReadList["!dir", String], {3}]; This use of "!command" in place of a file is at least partially documented under OpenRead: On systems that support pipes,OpenRead["!command"] runs the external program specified by command, and opens a pipe to get input from it. As ... 20 You can call an external (shell) command cmd without showing a command window by using the pipe syntax "!"<>cmd. This can be used in place of a filename with any Mathematica function that opens a file for reading. For example: Import["!dir", "Text"] Read["!dir"] (opens stream, must be closed) OpenRead["!dir"], followed by Read, ReadList etc to grab ... 19 Does this do the job? links = Import[ "http://www1.ncdc.noaa.gov/pub/data/cmb/drought/weekly-palmers/2005/", "Hyperlinks"] {"http://www1.ncdc.noaa.gov/pub/data/cmb/drought/weekly-palmers/2005/?C=N;O=D", "http://www1.ncdc.noaa.gov/pub/data/cmb/drought/weekly-palmers/2005/?C=M;O=A", "http://www1.ncdc.noaa.gov/pub/data/cmb/drought/weekly-palmers/... 18 Being the fan of Mathematica<->CLR interop that I am, your question has inspired me to try to get IronPython fully working with Mathematica for the last couple of days. I haven't yet had total luck. Part of my problem is that I don't have a Windows Mathematica license, so I can't fully double-check my work. While I'm trying to hunt down Mathematica for ... 18 Even the path is corrected, it still cannot run, since the argument type should {"double*", "double*"}. Here is my memo on calling dll created by gfortran using NETLink: Advantages of NETLink as compared to Mathlink: Fortran functions and subroutines can be called using NETLink without writing an additional C wrapper which is necessary in Mathlink. ... 17 I assume you have Maple to use. If so, Simply open Maple and type the Mathematica command itself directly into Maple using the FromMma package built-into Maple, like this: restart; with(MmaTranslator); #load the package (*[FromMma, FromMmaNotebook, Mma, MmaToMaple]*) and now can use it FromMma(Integrate[Cos[x],x]); One can also use Maple convert ... 16 I now have part of the picture. There is an undocumented function called HTTPClientOAuthAuthentication[] which takes only options as arguments. These options settings override defaults that are visible in HTTPClientOAuth.m. Here is an example of how to make get an OAuth 1.0a style access token, in this case for the Withings API: token = HTTPClient... 16 Have a look at this; http://reference.wolfram.com/mathematica/guide/MathLinkCLanguageFunctions.html I haven't used it in C/C++ but it works fine in C# and Java. Basically you create a connection to a Mathematica kernel and then pass it native data types. Works nicely. Here is some sample code in Java that I used when I first did this; import com.wolfram.... 16 The Run command returns the exit code of the program being run. In your case, the program is "!ls" which probably doesn't exist on your system (If you try sh -c '!ls -la$HOME' you'll also get an error). Why it returns 32512 instead of 127 (which is the return value I get by the shell) I don't know; however I notice that $32512 =127\cdot 256$, so I guess ...

15

See this link. I have found a solution. Works fine to me. Steps: 1-Create a script named runMath with the content: #!/usr/local/bin/MathematicaScript -script value=ToExpression[$ScriptCommandLine[[2]]]; (*The next line prints the script name.*) (*Print[$ScriptCommandLine[[1]]];*) Print[value]; 2-I gave execution privilege to the file. sudo chmod +x ...

14

Compress[expr] will take an expression, convert it to a string, using some form, which would allows to recover the expression later on (most likely InputForm is used) and compress the string. If the resulting compressed expression is uncompressed in an earlier version of Mathematica, the result is going to be an expression, which has no code associated ...

14

Mathematica 9 includes an RLink feature.

14

Erich Neuwirth on MathGroup mentioned a solution for Windows (free for non-commercial applications) that you can download here. Here is his example with small updates from Sasha and Mark Fisher. After downloading the R instalation and DCOM server stuff I tried it and it seems to work just fine. Needs["NETLink"] myR = CreateCOMObject["StatConnectorSrv....

14

To call Mathematica from Clojure, you will want to use Clojure's Java interop to access the Wolfram JLink classes to script Mathematica access. Start by launching Clojure with a classpath that includes the JLink.jar, for example with this batch file: @echo off set MATHEMATICA=C:/M/9.0 set JLINKJAR=%MATHEMATICA%/SystemFiles/Links/JLink/JLink.jar java -cp C:/...

14

I've got VBA calling Mathematica functions. It's not without issues, but maybe some other smart people here can help with the hiccups. First things first: The .dll that Mathematica includes with its installation for .NETLink is not COM-compatible, meaning that VBA cannot find entry points into the dll functions. To get around this, .NET must be installed ...

14

You create metafiles every time when you copy graphics from Mathematica FrontEnd and paste it in MS Word because it is native format for exchanging vector graphics under Windows. So your question is actually about corrupted metafiles in MS Word document opened on a machine without Mathematica fonts installed. This behavior is expected because unlike PDF and ...

13

Mathematica 8 automatically detects Intel version 11, but not Intel version 12 which was released later. In order to use the Intel 12 compiler, you'll need to set $CCompiler to point CCompilerDriver to where you've installed the Intel compiler: Needs["CCompilerDriver"]$CCompiler = {"Compiler" -> CCompilerDriverIntelCompilerIntelCompiler, "...

13

Yes, it is, but it's cumbersome (at least as of Mathematica 8). The hardest part is that you have to manually do a lot of the juggling required to work with .NET generics and extension methods. For example, let's translate a straightforward solution to Project Euler's Problem #1 ("Add all the natural numbers below one thousand that are multiples of 3 or 5.")...

Only top voted, non community-wiki answers of a minimum length are eligible