# Tag Info

43

2014-04-12 NOTICE: The recently released MATLAB R2014a contains a bug which partially breaks MATLink (it's not possible to MGet logical type variables, which in turn may have further consequences). If you depend on MATLink, please consider keeping MATLAB R2013b until the problem is sorted out. Due to the nature of the problem there is no quick workaround ...

26

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 ...

26

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} ...

22

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 ...

22

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 ...

20

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 ...

20

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"; ... 20 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 ... 18 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 = ... 18 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", ... 16 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 ... 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 ... 15 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 ... 15 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 ... 15 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 ... 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 = ... 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 ... 14 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 ... 13 Mathematica 9 includes an RLink feature. 12 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 ... 11 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 = ... 11 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 gortran using NETLink: Advantages of NETLink as compared to Mathlink: FORTRAN functions and subroutines can be called using .NET/Link without writing additional C wrapper which is necessary in Mathlink. ... 11 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 ... 11 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, ...

10

I am the author of the comp.soft-sys.math.mathematica message linked by Szabolcs, wherein I briefly mentioned a CDF extension for MediaWiki I have developed. In the few days since I sent that message, I have improved the extension so that meets MediaWiki's best practice guidelines for extensions, and added new features: it can show CDF files uploaded to a ...

10

Here I show the basic way to call MATLAB using NETLink under Windows via the MATLAB COM interface. This answer is Community Wiki, feel free to extend it to others platforms and/or improve it! In[1]:= Needs["NETLink`"] matlab = CreateCOMObject["matlab.application"] Out[2]= «NETObject[COMInterface[MLApp.DIMLApp]]» Now one can invoke MATLAB functions: ...

10

Begin Note: I have successfully got this working in the following environments. On a Mac PC running version 9.0.0.0 using a locally installed JRE (version 1.6.0_37). On a Windows PC running version 9.0.0.0 using a locally installed JRE (version 1.7.0_13). I found that on my Windows PC, the JRE included with Mathematica is version 1.6.0_10 and the method ...

9

Or simply use ReinstallNET["Force32Bit" -> True] which is a convenience function that calls UninstallNET[] InstallNET["Force32Bit" -> True]

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