0
$\begingroup$

I have a quite complex function of two-variables, let's say $\alpha(a,b)$ that has a parameter $c$ and I want to set this $c$ so that $\int_{-\infty}^{\infty} \alpha(a,b) \: \mathrm{d}a \: \mathrm{d}b = 0$. Sadly the function is too complex for Mathematica to calculate the complete analytical formula for $\int_{-\infty}^{\infty} \alpha(a,b) \: \mathrm{d}a \: \mathrm{d}b$, however, for every value of $a$ or $b$ (at least that I know of) we can find such an expression.

So for example for $b=0$ I have:

In: Integrate[alpha[r, 0, k] , {r, -\[Infinity], \[Infinity]},] 

Out: -2 k - Sqrt[\[Pi]]/3

So in this case I can simply set $k$ as the solution:

In: Solve[-2 k - Sqrt[\[Pi]]/3 == 0]

Out: {{k -> -(Sqrt[\[Pi]]/6)}}

Now my question is: how can I do this procedure with a single function? I have tried setting up an auxiliary function which has $k$ as an intermediate parameter:

intalpha[x_, y_] := ( 
  Solve[Integrate[
     alpha[xx, y, k], {xx, -\[Infinity], \[Infinity]}] == 0]; 
  alpha[x, y, k])

However, when trying to evaluate this function, the result still contains $k$:

In: intalpha[1, 0] 

Out: -((2 (k + Sqrt[\[Pi]] Erf[1] - 
    1/4 Sqrt[\[Pi]] (-1 + 4 Erf[1] + Erfc[1]^2)))/(E Sqrt[\[Pi]]))

The solution in my heas was to modify my one-liner as:

intalpha[x_, y_] := ( 
  k = Solve[
    Integrate[alpha[xx, y, k], {xx, -\[Infinity], \[Infinity]}] == 
     0]; alpha[x, y, k])

But this iterates over and over and the error message I get is that I exceed the recursion limit.

How do I set up a routine that calculates the integral of a given function with $k$ as a parameter, finds the value of $k$ for the integral to vanish and then return the value of the given function with this $k$ value?

$\endgroup$

1 Answer 1

1
$\begingroup$

I cannot try this without the definition of the function $\alpha(a,b;c)$, but here's a general solution:

Define the integral $A(c)=\int_{-\infty}^{\infty}\alpha(a,b;c)\,da\,db$:

A[c_?NumericQ] := NIntegrate[α[a, b, c], {a, -∞, ∞}, {b, -∞, ∞}]

You can plot $A(c)$ to get an idea of the desired solution $c$:

Plot[A[c], {c, 0, 1}]

You can find a numerical estimate of the solution $A(c)=0$ with

FindRoot[A[c] == 0, {c, 0.3}]

(assuming some starting-value guess, here $c_0=0.3$).

$\endgroup$

Your Answer

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