0
$\begingroup$

I need to numerically integrate a complex valued function of a real variable and a complex variable by the real variable. My integral:

$$ \int^1_{-1}\frac{e^{ix}}{x-z}dx ~~~\text{where} ~~x \in \mathbb{R}, z \in \mathbb{C}$$

I'm trying to do this:

z := x + I y; NIntegrate[Exp[I x]/(x - z), {x, -1, 1}]

But I get the message:

NIntegrate::inumr: The integrand (I E^(I x))/y has evaluated to non-numerical values for all sampling points in the region with boundaries {{0,1}}.

How can this integration be done numerically in Mathematica?

$\endgroup$
  • $\begingroup$ Welcome to Mathematica.SE DJNZ! You either need to give z a numerical value or use Integrate instead of NIntegrate. $\endgroup$ – Thies Heidecke Mar 22 at 3:36
  • $\begingroup$ Very thanks! I solve a more general problem: I have to integrate a large complex function over several real variables (this is such a parametrization), and I try to understand how to do it in general, and for this I try to make a prototype on a Mathematica. My target - make a calculation without decomposition into imaginary and real parts. $\endgroup$ – DJNZ Mar 22 at 3:49
  • $\begingroup$ If your general problem involves Cauchy principal values, you might want to arrange things so that "normal" integrals and principal value integrals are done separately. $\endgroup$ – J. M. will be back soon Mar 22 at 12:13
1
$\begingroup$
z := x + I*y;

Integrate[Exp[I*x]/(x - z), {x, -1, 1}]

(2 I Sin[1])/y

If you insist on using NIntegrate then you should provide numerical value to y?

$\endgroup$
  • $\begingroup$ Thanks for answer, but I wrote "I need to integrate numerically complex... ". Yes, but how to provide numerical value for y? How to set complex variable in general? $\endgroup$ – DJNZ Mar 22 at 3:42
1
$\begingroup$

I will assume that $z = a+ib$, since otherwise you are assuming that $x-z=iy$ which is always imaginary in your question. However, you do not even need to actually specify $z$ in that form. You just need to do this:

F[z_?NumberQ] := Integrate[Exp[I*x]/(x - z), {x, -1, 1}, PrincipalValue -> True]
F[1 + 2 I]
F[-I/2]
F[I/3]
F[0]

This gives

\begin{align} &e^{-2+i} (\text{Ei}(-2)-\text{Ei}(2-2 i))\\ &\sqrt{e} \left(-\text{Ei}\left(-\frac{1}{2}-i\right)+\text{Ei}\left(-\frac{1}{2}+i\right)-2 i \pi \right)\\ &\frac{\text{Ei}\left(\frac{1}{3}+i\right)-\text{Ei}\left(\frac{1}{3}-i\right)}{\sqrt[3]{e}}\\ &2 i \text{Si}(1) \end{align}

The last example is meant to show how it works when $z$ is real number, in which you need principal value integral. You could also change this to numerical case

G[z_?NumberQ] := 
 NIntegrate[Exp[I*x]/(x - z), {x, -1, z, 1}, Method -> PrincipalValue]

where you can account for when $z\in (-1,1)$ and you invoke PrincipalValue as "Method" (slightly different syntax than the Integrate command).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.