# Passing integration constants to self defined function

I would like to evaluate an integral I am taking in cylindrical coordinates, in which the integrand contains a previously defined function. I need to pass the r and phi integrand values to this function so that it can be evaluated. However I get the

"integrand has evaluated to non-numerical values for all sampling point errors"

when I do this. If I simply pass numbers to my function call in the integrand, it works fine. Here is the code, any help much appreciated!

Defined function:

SinsoidFluc[height_, factor_, scale_, x_, y_] :=
Which[x > 2*Pi, SinsoidFluc[height, factor, scale, x - 2*Pi, y],
x < -2*Pi, SinsoidFluc[height, factor, scale, x + 2*Pi, y],
y > 2*Pi, SinsoidFluc[height, factor, scale, x, y - 2*Pi],
y < -2*Pi, SinsoidFluc[height, factor, scale, x, y + 2*Pi],
x >= -2*Pi && x <= 2*Pi && y >= -2*Pi && y <= 2*Pi,
height - factor*Sin[x*scale]*Sin[y*scale]]


Would like to evaluate

PotentialCalc[height_, factor_, scale_, distance_] :=
1/(4*Pi)*NIntegrate[
SinsoidFluc[height, factor, scale, r*Cos[phi], r*Sin[phi]]*
distance*r/(r^2 + distance^2)^1.5, {r, 0, Infinity}, {phi, 0,
2*Pi}]


If I change the integrand to another defined functions, I still get the error.

    Hole[x_, y_, radius_, holefraction_] :=
Which[x^2 + y^2 <= radius, holefraction, x^2 + y^2 > radius, 1]

holefraction_?NumberQ, pitch_?NumberQ] :=
Hole[x - Round[x, pitch], y - Round[y, pitch], radius, holefraction]

PotentialCalc[potential_, factor_, radius_, pitch_, distance_] :=
1/(4*Pi)*NIntegrate[

• I cannot reproduce the error. PotentialCalc[2, 1, 1, 1] returns 1. without error. BTW, do you know about Mod[x, 2*Pi]? In particular Sign[x] Mod[Abs[x], 2 Pi] might replace the recursion in SinsoidFluc and speed up the computation. – Michael E2 Apr 9 '15 at 18:38
• Defining as SinsoidFluc[height_?NumberQ,...] will keep it effectively a black box function. So the minimization code will not attempt any symbolic processing that gives rise to such messages. – Daniel Lichtblau Apr 9 '15 at 19:41