Part III : Dealing with data

Module 4 : Numerical Integration

 
5 Evaluating the error function
Consider the error function data given in Table. 3. By definition, ${\mathrm{erf}}(z) = \frac{2}{\sqrt{\pi}}\int_0^z \exp{(-x^2)} dx$. Thus, one can verify the tabulated values by carrying out the integration numerically. Note that this integration is carried out on a function and not on discrete data as in the earlier cases. Here is the script which will evaluate the error function values for the given $z$ value.
% Define the error function
function y = f(x)
y = 2.*exp(-x*x)/(sqrt(pi));
endfunction
% Integrate the function from 0 to the given z value
quad("f",0,-2.0)
quad("f",0,-1.5)
quad("f",0,-1.0)
quad("f",0,-0.5)
quad("f",0,0.)
quad("f",0,0.5)
quad("f",0,1.)
quad("f",0,1.5)
quad("f",0,2.0)