I purchased (some time ago) a copy of William Shaw's Complex Analysis with Mathematica, published in 2006. He uses MathLink (something I've never done before) to speed up a Mandelbrot application. Here is his template file, named mandel.tm.

:Function:   fractalml
:Pattern: FractalML[a_?NumberQ,b_?NumberQ,{{c_?NumberQ,d_?NumberQ},{e_?NumberQ,f_?NumberQ}},g_Integer] 
:Arguments:  { N[a],N[b],N[c],N[d],N[e],N[f],g }
:ArgumentTypes: { Real,Real,Real,Real,Real,Real,Integer}
:ReturnType:   Manual

And here is his c-code, named mandel.c.

#include "mathlink.h"

void fractalml(double x0,double y0, double xmin, double xmax, double ymin, double ymax, int divs)
  double x, y, dist, xadd, yadd, temp;
  int xco, yco, counts;


  for(yco = 0; yco <divs; yco++){
  yadd = ymin + (ymax-ymin)*yco/(divs-1.0);

  for(xco = 0; xco <divs ; xco++){

  x = x0;
  y = y0;
  xadd = xmin + (xmax-xmin)*xco/(divs-1.0);

  dist = x0*x0+y0*y0;
  for(counts = 0; counts<100 && dist < 10000; counts++){
  temp = x*x-y*y+xadd;
  y = 2*x*y+yadd;
  x = temp;
  dist = x*x+y*y;

int main(int argc, char *argv[])
return MLMain(argc, argv);

There is another file (I think it is the compiled file of mandel.c?) named mandel in his folder binMacOSX. All of the files that I have mentioned are included on a CD with his book. I copied his cd files to my MacBook pro (Sierra OS X and Mathematica 11.1.1), then I followed Shaw's first instruction as follows:


Then I tried his second instruction:


After about three minutes I had to abort. It did not install.

Again, I've never tried to do something like this before, so are there suggestions that might work with his code?


  • 2
    $\begingroup$ This does not directly answer the question, but if the book has equivalent WL code you might try redefining it to use Compile with the target language set to "C". $\endgroup$ Jun 27, 2017 at 15:45
  • 1
    $\begingroup$ Here's a Mandelbrot implementation with Compile. It may very well be faster than the MathLink program above. $\endgroup$
    – Szabolcs
    Aug 30, 2017 at 10:26

1 Answer 1


The C code needs to be compiled before it can be used. If the code came with a pre-compiled binary, it may still not work. Macs used a different architecture back in 2006.

To compile the code, first you need a supported C compiler. On a Mac:

  • Install XCode from the Mac App Store
  • From a terminal, run xcode-select --install

Test that the compiler works in Mathematica, like this:


It should list Clang.

Now SetDirectory to where mandel.tm and mandel.c are and use

CreateExecutable[{"mandel.tm", "mandel.c"}, "mandel", "TargetDirectory" -> "."]

This will create an executable named mandel in the same directory. You can use it with Install:


Above I showed the automated method to compile. A step by step guide for manual compilation is here:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.