MathGroup Archive 2001

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

Search the Archive

Re: Using a Mathematica's function in a C program


Hi,

here is a function that request the numerical evaluation of
n function values of mathFuncSymbol[x1,x2,x3] for a list
{x1,x2,x3,y1,y2,y3,....}

@=:Evaluate: MapNApply[fun_Symbol,l_List]:=Map[N[Apply[fun,#]] &,l] 
@>@|



void GetFValuesFromMath(char *mathFuncSymbol,double *f, point3d *p, int
n)
{ double *vptr;
  int i;
  long cnt;

  MLPutFunction(stdlink,"EvaluatePacket",1L);
	 MLPutFunction(stdlink,"MapNApply",2L);
      MLPutSymbol(stdlink,mathFuncSymbol);
      MLPutFunction(stdlink,"List",n);
      for(i=0; i<n; i++)
        MLPutRealList(stdlink,(double *)(p+i),3L);
  while(MLNextPacket(stdlink) !=RETURNPKT)
	 MLNewPacket(stdlink);
  MLGetRealList(stdlink,&vptr,&cnt);
  memcpy(f,vptr,cnt*sizeof(double));
  MLDisownRealList(stdlink,vptr,cnt);
  for(i=0; i<n; i++)
    f[i]-=c;
}


and mathFuncSymbol[] is send to the top level ML function.

Regards
  Jens

Julie RIGAUD wrote:
> 
> Hi !
> I'm using Mathlink with a C program.
> Is it possible to declare a function in Mathematica and use  and evaluate it in the C program ?
> (for the moment, i'm trying to resolve my problem by using MLGetFunction( ) but it doesn't seem to work ...)
> Thanks a lot for your response.
> Julie
> 
>


  • Prev by Date: SplineFit - Parametrization ?
  • Next by Date: Re: FullGraphics with Graphics3D
  • Previous by thread: Using a Mathematica's function in a C program
  • Next by thread: Function Coloring with ParametricPlot3D