# Finding area under a PDF

Suppose I have a PDF with mean a and standard deviation b defined as below. How would I go about, finding the area under the PDF curve from 1 to 8, and then divide that value by the area from 0 to 8? After, that, I want to divide 7 by that number. Here is the code.

Given, what I said, I know the output should be greater than 7, but for some reason, I am getting 0.16.

a=1/2Erfc[k/Sqrt[2]] * x
k=0.2
b= -q Log[2, q] - (1 - q) Log[2, 1 - q]
q=a/x
x=7

N[
x/(
(CDF[NormalDistribution[a,b],8]-CDF[NormalDistribution[a,b],1])/
(CDF[NormalDistribution[a,b],1]-CDF[NormalDistribution[a,b],0])
)
]

• Never mind, I found the error. But, can anyone explain why, as k increases, the output increases as well? – sde7 Nov 24 '18 at 2:15
• If you found your error it's worth posting that as a self-answer. If you have new questions as a new question. – b3m2a1 Nov 24 '18 at 2:30

## 2 Answers

It sounds like you found the error which is that in your 3rd CDF command, you're asking for the value at 1 when it should be the value at 8.

The reason that the output increases as you increase k has to do with the way the mean and standard deviation are defined here. As k increases your mean and standard deviation drop to zero.

If we look at your output value as x/(r/s), that's the same as x*s/r. Because your PDF is centred at 0 with a very narrow standard deviation (for high k), your CDF from 1 to 8 is basically just 0 (this is r in the above definition). This means that your value rapidly approaches infinity.

If you're interested in seeing this in action, you can try running this code which shows how your PDF changes with k:

x = 7;
a[k_] := 1/2 Erfc[k/Sqrt[2]]*x;
q[k_] := a[k]/x;
b[k_] := -q[k] Log[2, q[k]] - (1 - q[k]) Log[2, 1 - q[k]]
cdf[val_, k_] := CDF[NormalDistribution[a[k], b[k]], val]
Manipulate[
Plot[
PDF[NormalDistribution[a[k], b[k]], y],
{y, -1, 8},
PlotRange -> Full,
Epilog -> {
Text[N[x/((cdf[8, k] - cdf[1, k])/(cdf[8, k] - cdf[0, k]))],
Scaled[{0.85, 0.9}]]
}],
{{k, 0.2}, 0, 4}]


The number in the top right of the plot is the number you were looking for. Sorry for the lack of labels and formatting on the plot.

• After re-examining, I realized I was asking for the wrong output. Instead of having Text[N[x/((cdf[8, k] - cdf[1, k])/(cdf[8, k] - cdf[0, k]))], I was really looking for Text[N[x/((cdf[1, k] - cdf[0, k])/(cdf[8, k] - cdf[0, k]))]. Your graphic helped me see that. Thank you! – sde7 Nov 24 '18 at 18:36

The area below a PDF is the integral of the PDF between $$x_1, x_2$$, so given the rest of your manipulations

res = 7*Integrate[PDF[NormalDistribution[a, b], x], {x, 0, 8}]/
Integrate[PDF[NormalDistribution[a, b], x], {x, 1, 8}]


for any a,b you have calculated earlier. I would subsitute everything in this fomula, no need for definitions outside it.