from Fresnel integral by Bora Ung
Computes the Fresnel integral with complex argument "z"

FresnelI(z, tol)
function [FresnelI] = FresnelI(z, tol)

%***********************************************************************
%     Computation of the complex Fresnel integral
%***********************************************************************
%
%     Program author: Bora Ung
%                     Department of physics
%                     University Laval
%                     Pavillon Alexandre-Vachon
%                     Quebec, Canada
%                     G1K 7P4
%                     bora.ung.1@ulaval.ca
%
%     Date of this version:  December 12, 2007
%
%***********************************************************************
%   DESCRIPTION:
%   This function computes the Fresnel integral "FresnelI(z)"
%   with argument "z" either real or complex, and where
%   FresnelI(z) = FresnelC(z) + i*FresnelS(z)
% ***********************************************************************
%   
%   USAGE:        [FresnelI] = FresnelI(z, tol)
% 
%   INPUT PARAMETERS:
%   z = complex argument of Fresnel integral (vector).
%   tol = absolute tolerance to evaluate the integral using "quadl"(scalar)
%   
%   REFERENCES: 
%   [1] A. Erdelyi, Higher Transcendental Functions, Vol.2, 
%       McGraw-Hill (1953)
%   [2] M. Abramowitz and I.A. Stegun, Handbook of Mathematical Functions,
%       New York, Dover Publications (1965)
%   
%***********************************************************************

if nargin < 2, tol = 1.0e-4; end  % default tolerance

nz = length(z);
FresnelI = zeros(1,nz);
i = sqrt(-1);

% We use the relation between the Fresnel integral and the "erf" function
% in order to evaluate the former.
z = sqrt(pi/4)*(1-i)*z;

for n = 1:nz
    FresnelI(n) = (1+i)/sqrt(pi)*quadl('exp(-t.^2)', 0, z(n), tol);
end

Contact us at files@mathworks.com