%Cumulative normal distribution function %We test different approximations of the cdf %clear memory and screen clear all; clc; %Partition a=-3; b=3; stepsize=0.01; x=a:stepsize:b; %Use the function of Matlab tic Matlab = normcdf(x); toc %Use de approximation described in Hull tic Hull = NORMDISTHULL(x); toc % Integration using built in Matlab functions tic lb = -100; %lower bound NumIntQuad = zeros(length(x),1); f = @(y) exp(-0.5*y.*y)/sqrt(2*pi); %standard normal density function for i=1:length(x) ub = x(i); %upper bound NumIntQuad(i)=quad(f,lb,ub); end toc %Create a plot figure plot(x,Matlab,'-b'); grid on hold on plot(x,Hull,'-.r'); plot(x,NumIntQuad,':g'); hold off xlabel('x') ylabel('Normal cdf') title(['Estimation of the cumulative normal distribution function']) legend('Matlab','Hull','Numerical integration') %% %----------------------- %CLOSER LOOK TO THE TAIL %----------------------- %Partition a=-10; b=-5; stepsize=0.01; x=a:stepsize:b; %Use the function of Matlab tic Matlab = normcdf(x); toc %Use de approximation described in Hull tic Hull = NORMDISTHULL(x); toc % Integration using built in Matlab functions tic lb = -100; %lower bound NumIntQuad = zeros(length(x),1); f = @(y) exp(-0.5*y.*y)/sqrt(2*pi); %standard normal density function for i=1:length(x) ub = x(i); %upper bound NumIntQuad(i)=quad(f,lb,ub); end toc %Create a plot figure plot(x,Matlab,'-b'); grid on hold on plot(x,Hull,'-.r'); plot(x,NumIntQuad,':g'); hold off xlabel('x') ylabel('Normal cdf') title(['Estimation of the cumulative normal distribution function']) legend('Matlab','Hull','Numerical integration')