Hi,
I need to integrate e^-(x^2) between negative infinity and positive infinity, now the function vanishes to a minute value much before negative and positive infinity.
I need to approximate the integral using the trapezium rule, which I have coding for but I just don't know how to apply it to the function.
Here is my coding for the trapezium rule:
def trap1 (f,a,b,delta , maxtraps=512):
n=8
inew= trap0(f,a,b,n)
iold=- inew
while ( fabs(inew - iold)>delta * fabs( inew )):
iold= inew
n=2*n
if n> maxtraps:
print " Cannot reach requested accuracy with", \
maxtraps , " trapezia"
return
inew= trap0 (f,a,b,n)
return inew
Note sure if I have the indentation right; 'n' is the number of trapeziums or widths I take, delta is just a small number I specify.
I basically need to apply the function f as e^-(x^2) and I need to alter the trapezium coding such that it gives me a good approximate for the integral - so I'm guessing I take some -100 to 100 as my 'a' and 'b' values.
Is the above coding the correct basis for the trapezium rule as well?
Thanks!