9 Replies Latest reply: May 21, 2017 2:37 PM by LucMeekes RSS

    Integration calcul problem on Mathcad 14

    yfleury Copper

      Hi everyone,


      I'm currently using Mathcad 14 and I think there is a problem in the software about the integration calcul.

      I define a function as a density of probability, so its integral should be 1, but I don't get 1 with some certain bounds. In the picture I have enclosed to the question, you can see that when I integrate a normal law of parameters (μ=100,σ=1) on the interval [90,110], the result is 1. But when I integrate the same function on the interval [0,∞[, the result is 0.

      Does anyone has already faced this problem ? Do you know if there is a patch to correct this mistake ?


      TIA for your answers guys.



        • Re: Integration calcul problem on Mathcad 14
          LucMeekes Platinum

          Mathcad 11:

          I can understand that the numerical integration from 0 to infinity gives a 0 result, because the numerical integrator might take big steps and miss the narrow peak at x=100.

          You can see that if you split the integration into two, one from 0 to 100 and the other from 100 to infinity would give you the desired 1. Also with a less drastic upper limit, 200 instead of infinity, gives 1.

          But the symbolic processor should not be fooled, so I was surprised by two answers. The symbolic integration of 0 to infinity, until I realised that adding the = again calls for numeric solution.

          The other is the integral of 100 to infinity. Apparently the symbolic processor really doesn't know the dnorm function.

          So, numeric integration of the the function alpha from 0 to infinity gives 0 is not a bug. You should investigate your function and if it is weirdly shaped, like alpha,

          you should expect weird answers.



          • Re: Integration calcul problem on Mathcad 14
            WE Platinum

            > I define a function as a density of probability, so its integral should be 1

            Not exactly - it should be exactly 1 if the lower limit is -infinity. With your lower limit of 0 you miss approx 1.3*10^2174



            As Luc already explained its a numerical issue, not a bug.

            For numerical integration the interval from lower to upper bound is divided into a number of segments where the function is evaluated.

            "infinity"  for the numeric processor is 10^307.

            I dont know the exact algorithm used by Mathcad but chances are, the intervals this huge range is diviided into are that big, the no function value is significantly over 0.

            Mathcads numerics should simply refuse to evaluate improper integrals with limits +-infinity but obviously it doesn't.


            You can influence the outcome by changing the value of the system variable TOL, but of course no value of TOL would give you the desired result for a limit infinity (10^307).

            Normally the advice would be to evaluate improper integrals only with Mathcads symbolics, but in this case its not possible as the symbolics is not aware of the dnorm function.

            Only way round I see is to define the function for the normal distribution yourself (DNorm in my example) and evaluate symbolically:


            EDIT: Ahh ! Luc was faster with his second reply

            • Re: Integration calcul problem on Mathcad 14
              yfleury Copper

              Thanks a lot Luc and Werner for your very clear answers, I now understand why those results are like that but I still find it ... strange !


              The problem is that I found that "problem" because I was intended to code a function who generate the pdf from the sum of 2 continuous variables.

              You may know that you can calculate this pdf with the convolution product of your variables, so I code this but it didn't work so much.


              When the 2 distributions are close ( I mean that their graphic representation had some commun points ), you've got almost a pdf ( integral of μ=0.994).


              But, as soon as you change one pdf, it goes wild !


              I also find this :

              So, do you think I had to exprimate my bounds in function of the mean and the variances of my pdf ? I don't have any other ideas ...


              Thanks again Luc and Werner.