# Question on the error function and when I can evaluate it numerically

1. Jun 19, 2013

### trmcclain

1. The problem statement, all variables and given/known data
I'm working with a particularly malicious mass model function given as:
λ^n*exp(-x^2)*(λ+x)^-n, λ=constant, n=constant (1.8 for those who care)

The first round of integration by parts using
u=(λ+x)^-n, du=-n(λ+x)^(-n-1)dx
dv=exp(-x^2), v=sqrt(pi)/2*erf(x)
Gives me:
(λ+x)^-n*[sqrt(pi)/2]*erf(x) + [n*sqrt(pi)/2]*∫erf(x)*(λ+x)^(-n-1)dx

Now I know for any given value of x, the erf(x) has a known value. C++ even has a function for it.
My question is, is it good math to utilize the fact that erf(x) for any finite value is known and constant to pull it out of the integral? Or do I need to utilize a different integration technique to solve this equation?
For anyone interested, I am trying to use this equation as a probability density model to randomly scatter points.
1. The problem statement, all variables and given/known data

2. Relevant equations

3. The attempt at a solution

2. Jun 19, 2013

### HallsofIvy

I'm not sure what you are asking here. It certainly is correct to "look up" the value of erf(x) or use computer function for it, just as you can use tables of trig functions or logarithms or use functions on a calculator or computer languages.

3. Jun 19, 2013

### trmcclain

My question is can i use that value for the erf(x) in order to take it out of the integral. If not, then I have to integrate it which will cause many headaches...

4. Jun 19, 2013

### SteamKing

Staff Emeritus

sin(x) and cos(x) and several other functions also meet your criterion that they evaluate to a constant for any value of x. Yet it is not true to say that

Int (sin(x) dx) = sin (x) * Int dx = x * sin (x)

Int (cos(x) dx) = cos (x) * Int dx = x * cos (x)

which are obviously wrong.

Some integrals do not have a closed form solution in terms of other elementary functions.
Look at a copy of Abramowitz & Stegun: http://people.math.sfu.ca/~cbm/aands/toc.htm

There are several definite integrals tabulated here [one of which is erf (x)] which have no representation in terms of the elementary functions but for which values can be tabulated.

5. Jun 19, 2013

### Ray Vickson

$$\int \text{erf}(x) (x+\lambda)^{-n-1} \, dx$$
equals
$$\text{erf}(x) \int (x+\lambda)^{-n-1} \, dx$$ the answer is NO! Never, never, ever assume something like that!

6. Jun 19, 2013

### trmcclain

Firstly - damnit. When you bring up trig it sort of slapped me in the face that of course I can't do that.
Secondly - awesome resource. But my problem remains.
If I try to perform a definite integral on the erf(x), not only does a gaussian appear, but also another erf(x) this time with an x multiplying in.
Would this not repeat ad infinitum the more I apply integration by parts?

7. Jun 19, 2013

### trmcclain

I realize this now, and I am glad that I asked first before just rolling with it.

8. Jun 19, 2013

### trmcclain

Bump for more help.
If I must perform a definite integral on erf(x)*f(x), and I don't want to do an infinite number of integration by parts (I really don't have the time), than what is the next step?

9. Jun 19, 2013

### Office_Shredder

Staff Emeritus
Do you need a closed form solution of this integral? It seems like numerical integration is probably sufficient if you're just going to run stochastic simulations for example

10. Jun 19, 2013

### trmcclain

Closed form in the sense of finite, yes. The equation is part of a probability density which I am using to scatter particles randomly using Newton-Raphson's Method. In order to do that, the function must be integrated from 0 to a finite upper limit.

11. Jun 19, 2013

### haruspex

You will have to use some kind of approximation, and this might mean breaking up the integration range, using different approximations in different ranges. E.g. for x small compared to lambda, you can expand the (x+λ)−n term binomially.

12. Jun 19, 2013

### SteamKing

Staff Emeritus
Your integral can be evaluated numerically. For your particular integrand, either Simpson's First Rule or a Gaussian Quadrature would probably give good results.

The Simpson's Rule would require that the interval of integration be divided into an even number of subdivisions, where n >= 2, and the integrand would be evaluated at each point within the interval and at the endpoints.

The Gaussian Quadrature method uses a set of irregularly spaced abscissa locations within the interval of integration. Once the function ordinates are obtained, a set of weighting factors is applied to determine the value of the integral.

Simpson's Rule is explained here: http://mathworld.wolfram.com/SimpsonsRule.html

If these don't explain things well enough, there are many other articles online. A careful search will also turn up program code which implement these methods.

13. Jun 19, 2013

### trmcclain

Thank you for this. It happens that my n=1.8. Does this rule out Simpson's Rule?

14. Jun 19, 2013

### haruspex

I suspect SteamKing was using n to stand for the number of intervals.

15. Jun 19, 2013

### trmcclain

*facepalm* Got it.