7
$\begingroup$

I solved some equation in Mathematica and I obtained something like $$y(t)=\exp \left\lbrace \left[ \text{erf}^{-1} (\text{i}t) \right]^2\right\rbrace, (1)$$ where $\text{i}$ is imaginary unit and $\text{erf}^{-1}(x)$ is the inverse error function (it is not equal to $\frac{1}{\text{erf}(x)}$ !!), which is defined for $x \in [-1,1]$. The problem is that the $t$ is real and the function has to be also real, but I can't plot this function since $\text{erf}^{-1}$ accepts only real arguments in Mathematica. Is there any way how to plot the solution or convert it to some other expression, which can be plotted? I tried to use some approximations of inverse error functions, such as $$ \text{erf}^{-1}(x) = \sum_{k=0}^{N} \frac{c_k}{2k+1}\left(\frac{\sqrt \pi}{2}x\right)^{2k+1}, (2)$$ to finite $N$ (from http://en.wikipedia.org/wiki/Error_function#Inverse_functions) which holds if $x \in [-1,1]$ and then I just simply put $t \rightarrow \text{i}t$ in approximated version of (1) and obtained only real part (imaginary part was zero), but I'm not sure wheather it is correct.

$\endgroup$
  • $\begingroup$ Can you show the Mathematica code? Because when I typed y = Exp[(Erf[I t]^(-1))^2]; Plot[y, {t, -1, 1}] I get this !Mathematica graphics $\endgroup$ – Nasser Nov 1 '14 at 19:24
  • 1
    $\begingroup$ The $\text{erf}^{-1}(x)$ is not $\frac{1}{\text{erf}(x)}$, but an inverse function of $\text{erf}(x)$, as explained above. The $\text{erf}^{-1}(x)$ function is represented in Mathematica as InverseErf[x]. The code I use is Plot[{Re[Exp[InverseErf[I x]]^2], Im[Exp[InverseErf[I x]]^2]}, {x, -1, 1}] $\endgroup$ – George Nov 1 '14 at 19:54
  • $\begingroup$ From help for InverserErf it says Explicit numerical values are given only for real values of s between -1 and +1. But you have complex arguments. $\endgroup$ – Nasser Nov 1 '14 at 20:10
  • 1
    $\begingroup$ On functions.wolfram.com/GammaBetaErf/InverseErf/04/01 you can read that InverseErf is a function $\mathbb{C} \rightarrow \mathbb{C}$. I'm asking how to modify the expression $\text{erf}^{-1}(\text{i}t)$ so it can be plotted. $\endgroup$ – George Nov 1 '14 at 21:13
  • $\begingroup$ It looks like Matlab might be able to do complex inverse error function calculations, see "To compute the inverse error function for complex numbers, first convert them to...". A Mathematica fix would be best, obviously, but I'm not sure how to do that. You can always check the quality of your series approximation $\text{Erf}^{-1}(iz)$ by feeding the result to Erf and see how close the result is to $iz$. Have you tried that, to see if your approximation is any good? $\endgroup$ – DumpsterDoofus Nov 2 '14 at 15:47
6
$\begingroup$

Unfortunately Mathematica seems to be a bit silly here, but a little math can give a workaround. In particular, we have $$\text{Erf}^{-1}(iz)=i\text{Erfi}^{-1}(z)$$ which means $$y(t)=\exp\left(-\text{Erfi}^{-1}(t)^2\right)$$ and $\text{Erfi}$ is purely real-valued for real $t$.

Because of this, if you are simply interested in plotting $y(t)$, then one way to do it is to avoid the inverse-map altogether, forward-map the $x$-axis, and then take that into account when constructing the plot:

ListLinePlot[Table[{Erfi[t], Exp[-t^2]}, {t, -2, 2, 0.1}], 
 PlotMarkers -> Automatic]

enter image description here

From this same approach, you can also define an interpolating function based on the above datapoints using the function Interpolation, and get reasonably accurate estimates of $y(t)$ at arbitrary $t$. The advantage of this approach is it avoid the use of complicated series approximations, and is still very accurate.

Additional unrelated fun stuff: the $\text{Erf}$ function maps purely imaginary values to purely imaginary values in a 1-to-1 manner, so it makes sense that $\text{Erf}^{-1}(iz)=if(z)$ for some real-valued function $f$. A visual proof of this fact can be obtained by plotting the sign of the imaginary component of $\text{Erf}(z)$ times a function which has peaks when the phase of $\text{Erf}(z)$ is $\pm\pi/2$:

hue = Compile[{{z, _Complex}}, {(1.0 Arg[-z] + \[Pi])/(2 \[Pi]), 
    Exp[1 - Max[Abs[z], 1]], Min[Abs[z], 1]}, 
   CompilationTarget -> "C", RuntimeAttributes -> {Listable}];
CCompile\[DoubleStruckCapitalC][expr_] := 
  Compile[{{z, _Complex}}, Evaluate[expr], CompilationTarget -> "C", 
   RuntimeAttributes -> {Listable}];
dat = CCompile\[DoubleStruckCapitalC][Erf[z]][
   Outer[Complex, Range[-5, 5, 0.015], Range[-5, 5, 0.015]]];
f[c_] := Sign[Im[c]]/(
  Abs[Arg[c] - \[Pi]/2] Abs[\[Pi]/2 + Arg[c]] + 0.1);
Image[hue[Map[f, dat, {2}]\[Transpose]/7], ColorSpace -> Hue]

enter image description here

The principal branch of the inverse function is the vertical line (which is what we want), and the other lobes are other branches of $\text{Erf}^{-1}$.

$\endgroup$
  • $\begingroup$ This looks amazing, thank you for help. I found out the problem in Maple, but this is better since everything is in one MAthematica notebook. I also found out that is it okay to put z -> iz in the series above (2) and it fits with result obtained from Maple. $\endgroup$ – George Nov 7 '14 at 15:28
  • $\begingroup$ Any reason why you didn't do ParametricPlot[{Erfi[t], Exp[-t^2]}, {t, -2, 2}, AspectRatio -> 1/GoldenRatio]? $\endgroup$ – J. M. will be back soon Aug 23 '15 at 5:01
  • $\begingroup$ Oh~~That's a really smart way of plotting complex Inverse function @J. M. $\endgroup$ – Harry Aug 23 '15 at 5:13

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.