The JSL code below uses the trapezoid rule. You must enter the range of integration ("xmin" and "xmax"). Enter the function you want to integrate into the variable called "pdf". The trapezoid rule divides the range of integration into sevaral intervals, and approximates the area under the curve for each interval by the area of a trapezoid. But how many intervals do you use? The code approximates the area using 1 interval, then 2 intervals, so on. It keeps increasing the number of intervals until the incremental difference is less than "stop". That way you don't have to specify the number of intervals, the code just keeps going until it converges.
The example in the code is the standard normal distribution between -10 and 10. The code outputs the results into the log window: the number of intervals it used, and the answer it converged to. In this example. it takes 26 intervals, and converges to 1.00000000000001. The total area under the normal curve is 1. Pretty close I would say.
Also of interest to you may be the midpoint rule and Simpsons rule. See Wikipedia for details. The code below can be easily altered to use those other rules.
You can also use a data table to do numerical integration. The more rows you use to span the range of integration, the better the approximation.
The code is below:
Clear Globals();
xmin=-10;
xmax=10;
stop=0.0000000000001;
pdf=function( {x} , 1/(sqrt(2*pi()))*exp(-x^2/2) );
intervals=1;
last=0;
new=0;
flag=0;
while(flag==0,
intervals=intervals+1;
increment=(xmax-xmin)/intervals;
total=0;
for(i=1, i<=intervals, i++,
if(i==1, x=xmin);
if(i>1, x=x+increment);
total=total + ((pdf(x)+pdf(x+increment))/2)*increment;
);
last=new;
new=total;
diff=abs(last-new);
if(diff<=stop, flag=1);
);
show(intervals);
show(total);