       problem with using external functions

• To: mathgroup at smc.vnet.net
• Subject: [mg91547] problem with using external functions
• From: Valery Yundin <yundin at ifh.de>
• Date: Wed, 27 Aug 2008 06:40:46 -0400 (EDT)

Dear MathGroup,

I've a problem with using external functions defined in MathLink app.
I guess the problem is in the evaluation order. I'm giving more
details below.

This is the function template:
:Begin:
:Function: my_xfxM
:Pattern: xfxM[nset_Integer, x_Real, Q_]
:Arguments: {nset, x, Q}
:ArgumentTypes: {Integer, Real64, Real64}
:ReturnType: Manual
:End:

The function body (the return value is list of doubles):
void my_xfxM(const int nset, const double x, const double Q) {
vector<double> result = LHAPDF::xfxM(nset, x, Q);
double* c_result = &(*result.begin());
}

I'm defining another function in Mathematica:
(it should multiply list of values returned by fucntion call by reversed
list of another function call and drop first 7 elements.
eg. if xfxM(1, x, 100.) returns {x1, ..., x14} the result should be:
Plus@@{x8*y14,x9*y13,...,x14*y8})
myintegrand =
Function[{x, y},
(Plus @@ (Drop[xfxM[1, x, 100.] Reverse[xfxM[1, y, 100.]], 7]))]

Direct evaluation works well
myintegrand[0.5, 0.3]

But smth like this does not work:
myintegrand[x, y] /. {x->0.5, y->0.3}

And also when I try to integrate this function:
NIntegrate[myintegrand[x, y], {x, 0.001, 1}, {y, 0.001, 1},

The NIntegrate gives error message:
Drop::drop: Cannot drop positions 1 through 7 in xfxM[1,x,100.] \
xfxM[100.,y,1]. >>
NIntegrate::inum: "Integrand (7+xfxM[1,x,100.]\xfxM[100.,y,1])/(14000\
\x\y) is not numerical at {x,y} = {0.50048828125`,0.50048828125`}"

How should I define my function to make this work? I think the problem is
that Mathematica tries to evaluate function body with formal parameters
(of "Symbol" type) not with just numerical values.

--
With best regards, Valery Yundin.

• Prev by Date: Re: coloring leaves of a dendrogram
• Next by Date: Re: Eliminating intermediate results
• Previous by thread: "cannot find the required native library named JLinkNativeLibrary"
• Next by thread: Re: problem with using external functions