1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

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

  1. Jun 19, 2013 #1
    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. jcsd
  3. Jun 19, 2013 #2

    HallsofIvy

    User Avatar
    Staff Emeritus
    Science Advisor

    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.
     
  4. Jun 19, 2013 #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...
     
  5. Jun 19, 2013 #4

    SteamKing

    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper

    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.
     
  6. Jun 19, 2013 #5

    Ray Vickson

    User Avatar
    Science Advisor
    Homework Helper

    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!
     
  7. Jun 19, 2013 #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?
     
  8. Jun 19, 2013 #7
    I realize this now, and I am glad that I asked first before just rolling with it.
     
  9. Jun 19, 2013 #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?
     
  10. Jun 19, 2013 #9

    Office_Shredder

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    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
     
  11. Jun 19, 2013 #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.
     
  12. Jun 19, 2013 #11

    haruspex

    User Avatar
    Science Advisor
    Homework Helper
    Gold Member
    2016 Award

    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.
     
  13. Jun 19, 2013 #12

    SteamKing

    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper

    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.
     
  14. Jun 19, 2013 #13
    Thank you for this. It happens that my n=1.8. Does this rule out Simpson's Rule?
     
  15. Jun 19, 2013 #14

    haruspex

    User Avatar
    Science Advisor
    Homework Helper
    Gold Member
    2016 Award

    I suspect SteamKing was using n to stand for the number of intervals.
     
  16. Jun 19, 2013 #15
    *facepalm* Got it.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted