MathGroup Archive 2004

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

Search the Archive

Re: Extracting Interpolating Function via mathlink

  • To: mathgroup at
  • Subject: [mg50799] Re: Extracting Interpolating Function via mathlink
  • From: Mario Drobics <mario.drobics at>
  • Date: Wed, 22 Sep 2004 00:10:57 -0400 (EDT)
  • References: <ciomuh$r8l$>
  • Sender: owner-wri-mathgroup at

The best way to do this is to use lists in Mathematica which you convert 
to STL-vectors in in C++. When getting the list in C++ you get its 
header and its length first. Then you can resize the vector and read in 
the elements accordingly. This works very fast, also for long lists.

Roughly it works like this (not tested!):
void getVector (std::vector<T> & con)
   std::string name;
   long count;

   int const valType = MLGetNext(ml);
   if (valType == MLTKFUNC)
       char const * cstr;

       MLGetFunction(ml, &cstr, &count);
       name = std::string(cstr);
       MLDisownSymbol(ml, cstr);


       for (size_t i = 0; i < count; i++)
     throw error("expected a function");


Peter Saffrey wrote:
> I'm writing an application that interfaces with Mathematicas
> differential equation solving routines via mathlink. The equations are
> loaded and solved and then I need to extract the resulting
> interpolating functions for use in the rest of my application. At the
> moment, I have a mathematica function which dumps the data points, one
> by one, which I grab and insert into C++ objects. This works, but it's
> very slow on large functions - when there are 10000 data points, this
> takes about 30 seconds per function.
> I suspect the reason for the poor performance is that I'm calling too
> many mathlink functions - each data point is three "getpacket" calls,
> one for the a list header, and one for each part of the data point. Is
> there a way I can do this more quickly? How about exporting the whole
> list of points as some kind of C++ structure I can then parse with
> using mathlink? Does anybody know how I might do this?
> Thanks,
> Peter

  • Prev by Date: Re: Special case of plotting a 3D function
  • Next by Date: Re: Re: Re: Forcing a Derivative
  • Previous by thread: Re: Extracting Interpolating Function via mathlink
  • Next by thread: Special case of plotting a 3D function