function z=invQ(Q);
% z=invQ(Q) is the integral of the gaussian pdf (mu=0, sigma=1), from -Inf
% to z.

if any(Q<=0 | Q>=1), error('Need 0<Q<1'); end; 

t=(Q>=0.5);

a=2*((Q-0.5).*t + (0.5-Q).*(~t));

z=sqrt(2)*(t + (-1)*(~t)).*erfinv(a);

