I have a functions, which is an Integral. It is exaclty this function
Zf[x_] := 2*I*NIntegrate[Exp[-y^2.0 + 2.0*I*y*x], {y, 0, Infinity}];
Later I need to plot a graph of this function like this
Print["init time=", DateString[]]
Timing[Plot[Im[Zf[x]], {x, -2, 2}]]
Print["finish time=", DateString[]]
and it takes around 9 seconds.
but as final result I need to plot some more complicated functions, depends on this Zf like this.
f1[x_, p1_] := I*Im[Zf[x]] + p1*I*(1 + Zf[x]);
f2[x_, p1_, p2_] :=
p1*(f1[x] + (2 + Zf[x])/ Conjugate[Zf[x]]) -
I*p2*(f1[x] - (2 - Zf[x])/ Conjugate[Zf[x]]);
Here p1 and p2 some parameters. and later I plot it again like this
Print["init time=", DateString[]]
Timing[Plot[Im[f1[x, 2]], {x, -2, 2}]]
Print["finish time=", DateString[]]
Print["init time=", DateString[]]
Timing[Plot[Im[f2[x, 1.35, 1.45]], {x, -2, 2}]]
Print["finish time=", DateString[]]
and plotting of f1 takes around 30 seconds, plotting of f2 takes 90 seconds.
If I replace NIntegrate to normal Integrate, it becomes much slower (I even cannot plot first graph in 10 minutes).
The problem is much bigger because finally I need dozens of graphs with comparation of all that functions and different parameters. Also I would like to change parameters quickly and compare the results.
Print["init time=", DateString[]]
Timing[Plot[{Im[Zf[x]], Im[f1[x, 2]], Im[f2[x, 1.35, 1.45]],
Im[f1[x, 3]], Im[f2[x, 2.35, 2.45]]}, {x, -2, 2}]]
Print["finish time=", DateString[]]
It takes 240 seconds. Here is only 2 parameters. In real life it is much more complicated. I have around 10 parameters and functions more complicated than f1 and f2. It really takes hours.
Can I do something to improve performance of this kind of calculations?
Zf[x]has a nice closed form in terms of the Dawson integral; why not use that instead? – J. M.'s missing motivation Jun 18 '15 at 23:19