numerical integration


eleceng
04-05-2008, 08:48 PM
Hi guys, please I need your help in solving the integral from -infinity to 0 of an error function.
Can anyone help me?

Thank you.

davekw7x
04-06-2008, 05:08 PM
...integral from -infinity to 0 of...
There are a couple of general approaches to evaluating improper integrals, and a lot of specific methods for particular classes of functions.

So:

1. Exactly what it is that you want to integrate? Are you sure the function is integrable over that range? What are the accuracy requirements?

2, What is the purpose of the exercise? (Evaluate a particular interval? Learn numerical approaches to evaluation of improper integrals? Learn to write a program or function to evaluate a particular improper integral? What?)

3. What method (or methods) have you covered for evaluating a definite integral over a finite interval? How about error analysis?

4. What reference materials (textbook or whatever) do you have at your disposal?

5. What computer language do you have in mind? What compiler? What operating system? What is your level of experience in programming in general and in numerical methods in particular?

...Can anyone help...
That depends.

Maybe if you ask a specific question (or some specific questions) someone could at least know where you want to start.

Regards,

Dave

eleceng
04-06-2008, 05:48 PM
I am taking a digital communication course in my masters in electrical engineering. I am facing a problem where I should integrate a Q function ( which is an error function). I can use either Matlab or C. so my integral is the following:
\int_{-infty}^{0}\int_{r}{infty}e^(\frac{-t^2}{2})dtdr

if you can help me solve this double integral, i will really appreciate it, it can save my whole career! thank you.

davekw7x
04-07-2008, 01:16 PM
... my integral is the following:
\int_{-infty}^{0}\int_{r}{infty}e^(\frac{-t^2}{2})dtdr

I think that the inner integral defines a function of r as follows (Note a typo in my original post has been edited in blue below.)

f(r) = The integral from t = r to infinity of (exp(-t*t/2) dt)


I would (probably) have written the LaTex more like

\int_{-\infty}^{0}\int_{r}^{\infty}e^{(-t^2/2)}dt\,dr


If this is not the case, then please spell it out for us.

Then you want to integrate f(r) over the interval -infinity to zero. Now, as r gets very negative, the value of f(r) approaches the square root of (two * pi), so the integral of f(r) from -infinity to anything simply can't have a finite value.

If you want to look f(r) values for some negative r:

f(r) = integral from r to infinity of exp(-x*x/2.0) dx

We are interested in evaluating f(r) for negative values of r.

First note that the integral of exp(-x*x/2) dx from 0 to infinity
is equal to the square root of (pi/2), so f(0) is
approximately equal to 1.253314137

Then, for negative values of r, we have
f(r) = (The integral from r to zero of exp(-x*x/2) dx) + f(0)

Integral from -1 to 0 = 0.855624392 so f( -1) = 2.108938529
Integral from -2 to 0 = 1.196288013 so f( -2) = 2.449602151
Integral from -3 to 0 = 1.249930445 so f( -3) = 2.503244582
Integral from -4 to 0 = 1.253234749 so f( -4) = 2.506548887
Integral from -5 to 0 = 1.253313419 so f( -5) = 2.506627556
Integral from -6 to 0 = 1.253314135 so f( -6) = 2.506628272
Integral from -7 to 0 = 1.253314137 so f( -7) = 2.506628275
Integral from -8 to 0 = 1.253314137 so f( -8) = 2.506628275


Bottom line: Unless I'm missing something from your problem statement, you can't integrate f(r) from minus infinity since it doesn't even approach zero as r gets more and more negative.

So much for plan A. What's plan B?

Regards,

Dave

Footnote: Values of f(r) are easily obtained if your program library includes the complementary error function. Your f(r) is just the complementary error function with a little scaling. (A simple change of variables.)

For any (finite) r, the value of f(r) can be calculated as value = sqrt(M_PI/2.0)*erfc(r/sqrt(2.0));


If you don't have erfc(), then you can use just about any standard numerical integration formula to get the values for the definite integrals that I tabulated above.

eleceng
04-07-2008, 01:34 PM
well thanks Dave, I really appreciate your help. But the thing is that the inner integral is integral from r to infinity of exp(-t*t/2) dt.
Then I have to integrate the result from -infinity to 0 of the previous result over dr. Actually I can integrate from any negative integer to zero, because i dont think values close to -infinity are going to affect my result.
Thx again.

davekw7x
04-07-2008, 02:02 PM
But the thing is that the inner integral is integral from r to infinity of exp(-t*t/2) dt.
Oops. I had a typo in the post. I have now edited it out (I hope). I think my LaTeX was/is correct.

Then I have to integrate the result from -infinity to 0 of the previous result over dr.It still can't be done, since the integral is not finite.

Actually I can integrate from any negative integer to zero,

Then you can define f(r) something like this and let the library function for the complementary error function perform the inner integration.

float fnc(float r)
{
return sqrt(M_PI / 2.0) * erfc(r / sqrt(2.0));
}


If you are using Numerical Recipes functions, it is called erffc to distinguish it from common math library functions named erfc() (as in the GNU math library).

Then call a function like Numerical Recipes qromb() to perform your definite integration. Note that the Numerical Recipes C version for qromb() uses a pointer to a function that returns a float. The C++ Version 2 NR::qromb() function uses a pointer to a function with double return type, so make whatever change you need.

Regards,

Dave