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

In summary: Yes, it does. Simpson's Rule requires that n be a positive integer >= 2. Gaussian Quadrature can accommodate fractional n.
  • #1
trmcclain
14
0

Homework Statement


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.
 
Physics news on Phys.org
  • #2
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
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
To answer your question in a nutshell, no.

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
trmcclain said:

Homework Statement


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.

If you are asking whether
[tex] \int \text{erf}(x) (x+\lambda)^{-n-1} \, dx[/tex]
equals
[tex] \text{erf}(x) \int (x+\lambda)^{-n-1} \, dx[/tex] the answer is NO! Never, never, ever assume something like that!
 
  • #6
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
Ray Vickson said:
If you are asking whether
[tex] \int \text{erf}(x) (x+\lambda)^{-n-1} \, dx[/tex]
equals
[tex] \text{erf}(x) \int (x+\lambda)^{-n-1} \, dx[/tex] the answer is NO! Never, never, ever assume something like that!

I realize this now, and I am glad that I asked first before just rolling with it.
 
  • #8
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
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
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
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
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
Gaussian quadrature here: http://pomax.github.io/bezierinfo/legendre-gauss.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
SteamKing said:
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
Gaussian quadrature here: http://pomax.github.io/bezierinfo/legendre-gauss.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.

Thank you for this. It happens that my n=1.8. Does this rule out Simpson's Rule?
 
  • #14
trmcclain said:
Thank you for this. It happens that my n=1.8. Does this rule out Simpson's Rule?

I suspect SteamKing was using n to stand for the number of intervals.
 
  • #15
haruspex said:
I suspect SteamKing was using n to stand for the number of intervals.

*facepalm* Got it.
 

1. What is the error function and how is it used in numerical evaluation?

The error function, denoted as erf(x), is a mathematical function that is commonly used in statistics and engineering. It is used to calculate the probability of an event occurring between two values in a normal distribution. In numerical evaluation, the error function can be used to approximate the probability of an event occurring within a certain range, by evaluating it at different points.

2. Can the error function be evaluated numerically for any value of x?

Yes, the error function can be evaluated numerically for any real value of x. However, it is important to note that as x approaches infinity, the value of erf(x) approaches 1. Therefore, when evaluating the error function numerically, it is necessary to use a large enough range of x values to get an accurate approximation.

3. How do I evaluate the error function numerically using a computer program?

To evaluate the error function numerically using a computer program, you can use built-in functions or algorithms specifically designed for this purpose. For example, in MATLAB, you can use the erf(x) function, while in Python, you can use the scipy.special.erf(x) function. Alternatively, you can also use numerical integration methods to approximate the value of the error function.

4. What is the significance of the error function in statistics?

The error function is significant in statistics because it is closely related to the normal distribution, which is a common probability distribution used to model real-world phenomena. The cumulative distribution function of the normal distribution is directly related to the error function. This allows for the calculation of probabilities and confidence intervals in statistical analyses.

5. Are there any common mistakes to avoid when evaluating the error function numerically?

One common mistake to avoid when evaluating the error function numerically is using an insufficient range of x values. As mentioned earlier, as x approaches infinity, the value of erf(x) approaches 1. Therefore, using a limited range of x values may result in inaccurate approximations. It is also important to use appropriate numerical methods and to check for convergence to ensure accurate results.

Similar threads

  • Calculus and Beyond Homework Help
Replies
17
Views
2K
  • Calculus and Beyond Homework Help
Replies
5
Views
355
Replies
3
Views
216
  • Calculus and Beyond Homework Help
Replies
2
Views
1K
  • Calculus and Beyond Homework Help
Replies
4
Views
2K
  • Calculus and Beyond Homework Help
Replies
8
Views
947
  • Calculus and Beyond Homework Help
Replies
9
Views
1K
  • Calculus and Beyond Homework Help
Replies
1
Views
765
  • Calculus and Beyond Homework Help
Replies
28
Views
5K
  • Calculus and Beyond Homework Help
Replies
2
Views
868
Back
Top