// Numbas version: exam_results_page_options {"name": "Construct a probability distribution function, then find CDF and expectation", "extensions": ["stats"], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"variable_groups": [], "variables": {"tol": {"templateType": "anything", "group": "Ungrouped variables", "definition": "0.01", "description": "", "name": "tol"}, "e1": {"templateType": "anything", "group": "Ungrouped variables", "definition": "4/p^2*(((xu+xl)/2)^3-xl^3)/3", "description": "", "name": "e1"}, "a": {"templateType": "anything", "group": "Ungrouped variables", "definition": "0", "description": "", "name": "a"}, "e2": {"templateType": "anything", "group": "Ungrouped variables", "definition": "4/p^2(((xu)^2/2*xu-xu^3/3)-((xu+xl)^2/2*xu-(xl+xu)^3/3))", "description": "", "name": "e2"}, "exans": {"templateType": "anything", "group": "Ungrouped variables", "definition": "up-lo", "description": "", "name": "exans"}, "u": {"templateType": "anything", "group": "Ungrouped variables", "definition": "random(0..100)", "description": "", "name": "u"}, "xl": {"templateType": "anything", "group": "Ungrouped variables", "definition": "0", "description": "", "name": "xl"}, "j1": {"templateType": "anything", "group": "Ungrouped variables", "definition": "round((u*(xu+1)+(100-u)*(2*xu-1))/100)", "description": "", "name": "j1"}, "cval": {"templateType": "anything", "group": "Ungrouped variables", "definition": "precround(4/p^2,4)", "description": "", "name": "cval"}, "i1": {"templateType": "anything", "group": "Ungrouped variables", "definition": "round((t+(100-t)*(xu-1))/100)", "description": "", "name": "i1"}, "ans": {"templateType": "anything", "group": "Ungrouped variables", "definition": "precround(exans,2)", "description": "", "name": "ans"}, "ux": {"templateType": "anything", "group": "Ungrouped variables", "definition": "j1/2", "description": "", "name": "ux"}, "t": {"templateType": "anything", "group": "Ungrouped variables", "definition": "random(0..100)", "description": "", "name": "t"}, "xu": {"templateType": "anything", "group": "Ungrouped variables", "definition": "xl+random(4..15)", "description": "", "name": "xu"}, "lo": {"templateType": "anything", "group": "Ungrouped variables", "definition": "precround((2/p^2)*(lx-xl)^2,5)", "description": "", "name": "lo"}, "p": {"templateType": "anything", "group": "Ungrouped variables", "definition": "(xu-xl)", "description": "", "name": "p"}, "up": {"templateType": "anything", "group": "Ungrouped variables", "definition": "precround(1-(2/p^2)*(ux-xu)^2,5)", "description": "", "name": "up"}, "lx": {"templateType": "anything", "group": "Ungrouped variables", "definition": "i1/2", "description": "", "name": "lx"}}, "ungrouped_variables": ["a", "e1", "ux", "xl", "i1", "lo", "j1", "up", "exans", "p", "u", "t", "tol", "ans", "e2", "cval", "lx", "xu"], "question_groups": [{"pickingStrategy": "all-ordered", "questions": [], "name": "", "pickQuestions": 0}], "name": "Construct a probability distribution function, then find CDF and expectation", "functions": {}, "showQuestionGroupNames": false, "parts": [{"scripts": {}, "gaps": [{"answer": "{4}/{p^2}", "vsetrange": [0, 1], "checkingaccuracy": 0.001, "showCorrectAnswer": true, "expectedvariablenames": [], "notallowed": {"message": "

input as a fraction and not a decimal

", "showStrings": false, "partialCredit": 0, "strings": ["."]}, "showpreview": true, "checkingtype": "absdiff", "scripts": {}, "checkvariablenames": false, "type": "jme", "answersimplification": "std", "marks": 2, "vsetrangepoints": 5}], "type": "gapfill", "prompt": "\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
$f_X(x) = \\left \\{ \\begin{array}{l} \\phantom{{.}} \\\\ \\phantom{{.}} \\\\ \\phantom{{.}} \\\\\\phantom{{.}} \\\\ \\phantom{{.}} \\\\ \\phantom{{.}}\\end{array} \\right .$$0$ $ x \\leq \\var{xl},$
$cx$ $\\var{xl} \\lt x \\leq \\simplify[std]{{xu+xl}/2},$
$c(\\var{xu}-x)$ $\\simplify[std]{{xu+xl}/2} \\lt x \\leq \\var{xu},$
$0$$x \\gt \\var{xu}.$
\n \n \n \n

What value of $c$ makes $f_X(x)$ into the pdf of a distribution?

\n \n \n \n

Input your answer here as a fraction and not as a decimal.

\n \n \n \n

$c=\\;\\;$[[0]]

\n \n \n ", "showCorrectAnswer": true, "marks": 0}, {"scripts": {}, "gaps": [{"answer": "0", "vsetrange": [0, 1], "checkingaccuracy": 0.001, "checkvariablenames": false, "expectedvariablenames": [], "showpreview": true, "checkingtype": "absdiff", "scripts": {}, "type": "jme", "showCorrectAnswer": true, "marks": 0.5, "vsetrangepoints": 5}, {"answer": "(({2} / {(p ^ 2)}) * ((x + ( - {xl})) ^ 2))", "vsetrange": [0, 1], "checkingaccuracy": 0.001, "showCorrectAnswer": true, "expectedvariablenames": [], "notallowed": {"message": "

input numbers as fractions or integers and not as decimals

", "showStrings": false, "partialCredit": 0, "strings": ["."]}, "showpreview": true, "checkingtype": "absdiff", "scripts": {}, "checkvariablenames": false, "type": "jme", "answersimplification": "std", "marks": 1, "vsetrangepoints": 5}, {"answer": "(1 + ( - (({2} / {(p ^ 2)}) * ((x + ( - {xu})) ^ 2))))", "vsetrange": [0, 1], "checkingaccuracy": 0.001, "showCorrectAnswer": true, "expectedvariablenames": [], "notallowed": {"message": "

input numbers as fractions or integers and not as decimals

", "showStrings": false, "partialCredit": 0, "strings": ["."]}, "showpreview": true, "checkingtype": "absdiff", "scripts": {}, "checkvariablenames": false, "type": "jme", "answersimplification": "std", "marks": 1, "vsetrangepoints": 5}, {"answer": "1", "vsetrange": [0, 1], "checkingaccuracy": 0.001, "checkvariablenames": false, "expectedvariablenames": [], "showpreview": true, "checkingtype": "absdiff", "scripts": {}, "type": "jme", "showCorrectAnswer": true, "marks": 0.5, "vsetrangepoints": 5}], "type": "gapfill", "prompt": "\n \n \n

Given the value of $c$ found in the first part, determine and input the distribution function $F_X(x)$

\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
$F_X(x) = \\left \\{ \\begin{array}{l} \\phantom{{.}} \\\\ \\phantom{{.}} \\\\ \\phantom{{.}} \\\\ \\phantom{{.}} \\\\ \\phantom{{.}} \\\\ \\phantom{{.}}\\\\ \\phantom{{.}}\\\\ \\phantom{{.}} \\end{array} \\right .$ [[0]] $x \\leq \\var{xl},$
[[1]] $\\var{xl} \\lt x \\leq \\simplify[std]{{xu+xl}/2},$
[[2]] $\\simplify[std]{{xu+xl}/2} \\lt x \\leq \\var{xu},$
[[3]] $ x \\gt \\var{xu}.$
\n \n \n \n

Input all numbers as fractions or integers in the above formulae.

\n \n \n ", "showCorrectAnswer": true, "marks": 0}, {"scripts": {}, "gaps": [{"showCorrectAnswer": true, "allowFractions": false, "scripts": {}, "type": "numberentry", "maxValue": "ans+tol", "minValue": "ans-tol", "correctAnswerFraction": false, "marks": 1, "showPrecisionHint": false}], "type": "gapfill", "prompt": "\n \n \n

Also, using the distribution function above find:

\n \n \n \n

$P(\\var{lx} \\lt X \\lt \\var{ux})=\\;\\;$[[0]]

\n \n \n \n

(input your answer to $2$ decimal places).

\n \n \n ", "showCorrectAnswer": true, "marks": 0}, {"scripts": {}, "gaps": [{"answer": "{xu}/2", "vsetrange": [0, 1], "checkingaccuracy": 0.001, "showCorrectAnswer": true, "expectedvariablenames": [], "notallowed": {"message": "

Input your answer as an integer or a fraction and not as a decimal.

", "showStrings": false, "partialCredit": 0, "strings": ["."]}, "showpreview": true, "checkingtype": "absdiff", "scripts": {}, "checkvariablenames": false, "type": "jme", "answersimplification": "all,fractionNumbers", "marks": 1, "vsetrangepoints": 5}], "type": "gapfill", "prompt": "

Hence find the expectation

\n

 $\\displaystyle \\operatorname{E}[X]=\\int_{-\\infty}^{\\infty}xf_X(x)\\;dx$.

\n

$\\operatorname{E}[X]\\;=\\;$[[0]]

\n

Input your answer as an integer or a fraction.

", "showCorrectAnswer": true, "marks": 0}], "statement": "

A random variable $X$ has a probability density function (PDF) given by:

", "tags": ["CFD", "checked2015", "continuous random variables", "cr1", "cumulative distribution functions", "density functions", "distribution function", "distribution functions", "expectation", "integration", "MAS8380", "PDF", "pdf", "piecewise function", "probabilities", "probability density function", "random variables", "statistics", "tested1"], "rulesets": {"std": ["all", "fractionNumbers", "!collectNumbers", "!noLeadingMinus"]}, "preamble": {"css": "", "js": ""}, "type": "question", "metadata": {"notes": "

8/07/2012:

\n

Added tags.

\n

Checked calculations, OK.

\n

Set tolerance via new variable tol=0.01 for last question.

\n

23/07/2012:

\n

Added description.

\n

1/08/2012:

\n

Added tags.

\n

In the Advice section, moved \\Rightarrow to the beginning of the line instead of the end of the previous line.

\n

Question appears to be working correctly.

\n

21/12/2012:

\n

Checked calculations, OK. Added tag tested1.

\n

Checked rounding, OK. Added tag cr1.

", "licence": "Creative Commons Attribution 4.0 International", "description": "

The random variable $X$ has a PDF which involves a parameter $c$. Find the value of $c$. Find the distribution function $F_X(x)$ and $P(a \\lt X \\lt b)$.

\n

Also find the expectation $\\displaystyle \\operatorname{E}[X]=\\int_{-\\infty}^{\\infty}xf_X(x)\\;dx$.

"}, "variablesTest": {"condition": "", "maxRuns": 100}, "advice": "

a)
Note that in order for $f_X(x)$ to be a pdf it must satisfy two important conditions:

\n

1. $f_X(x) \\ge 0$ in the range $\\var{xl} \\le x \\le \\var{xu}$

\n

2. The area under the curve given by $f_X(x)$ is $1$ and this implies that:
\\[\\int_{\\var{xl}}^{\\var{xu}}f_X(x)\\;dx = 1\\] as the value of the function is $0$ outside this range.

\n

We first check condition 2. and then check that condition 1. is satisfied.

\n

Hence \\[\\begin{eqnarray*} \\int_{-\\infty}^{\\infty}f_X(x)\\;dx=\\int_{\\var{xl}}^{\\var{xu}}f_X(x)\\;dx&=&\\int_{\\var{xl}}^{\\simplify[std]{{xu+xl}/2}}cx\\;dx+\\int_{\\simplify[std]{{xu+xl}/2}}^{\\var{xu}}c(\\var{xu}-x)\\;dx\\\\
&=&c \\left[ \\frac{x^2}{2} \\right]_{\\var{xl}}^{\\simplify[std]{{xu+xl}/2}} + c\\left[\\var{xu}x - \\frac{x^2}{2}\\right]_{\\simplify[std]{{xu+xl}/2}}^{\\var{xu}}\\\\&=&\\simplify[std]{{(xu+xl)^2}/8}c+\\simplify[std]{{(xu-xl)^2}/8}c=\\simplify[std]{{xu^2+{xl^2}}/{4}}c \\end{eqnarray*} \\]

\n

But this has to equal $1$ and so \\[c=\\simplify[std]{4/{p^2}}\\]

\n

Hence with this value of $c$ we see that condition 2. is satisfied i.e.

\n

\\[\\int_{-\\infty}^{\\infty}f_X(x)\\;dx=1\\]

\n

Condition 1. is clearly satisfied as $c \\gt 0$.

\n

b)

\n

The Distribution Function

\n

We must have $F_X(x)=0,\\;\\;\\;x \\le \\var{xl},\\;\\;\\;\\textrm{and}\\;\\;\\;F_X(x)=1,\\;\\;\\;x \\ge \\var{xu}$

\n

Apart from that we find an expression for $F_X(x)$ in each of the ranges $[\\var{xl},\\simplify[std]{{xl+xu}/2}],\\;\\;\\;[\\simplify[std]{{xl+xu}/2},\\var{xu}]$

\n

1. $x \\in [\\var{xl},\\simplify[std]{{xl+xu}/2}]$

\n

We have:\\[\\begin{eqnarray*} f_X(x) &=& \\simplify[std]{{4}/{p^2}} x \\\\ \\Rightarrow F_X(x)&=& \\int_{-\\infty}^xf_X(u)\\;du \\\\ &=& \\simplify[std]{{4}/{p^2}}\\int_{\\var{xl}}^x u\\;du\\\\ &=&\\simplify[std]{{4}/{p^2}}\\left[\\frac{u^2}{2}\\right]_{\\var{xl}}^x\\\\&=&\\simplify[std]{{2}/{p^2}}x^2 \\end{eqnarray*} \\]

\n

2. $x \\in [\\simplify[std]{{xl+xu}/2},\\var{xu}]$

\n

We have:\\[\\begin{eqnarray*} f_X(x) &=& \\simplify[std]{{4}/{p^2}}(\\var{xu}-x) \\\\ \\Rightarrow  F_X(x)&=& \\int_{-\\infty}^xf_X(u)\\;du = \\int_{\\var{xl}}^{\\simplify[std]{{xl+xu}/2}}f_X(u)\\;du+\\int_{\\simplify[std]{{xl+xu}/2}}^x f_X(u)\\;du\\\\ &=& \\simplify[std]{{4}/{p^2}}\\int_{\\var{xl}}^{\\simplify[std]{{xl+xu}/2}} u\\;du + \\simplify[std]{{4}/{p^2}}\\int_{\\simplify[std]{{xl+xu}/2}}^x(\\var{xu}-u)\\;du\\\\&=&\\simplify[std]{{4}/{p^2}}\\left[ \\frac{u^2}{2} \\right]_{\\var{xl}}^{\\simplify[std]{{xu+xl}/2}} + \\simplify[std]{{4}/{p^2}}\\left[\\var{xu}u - \\frac{u^2}{2}\\right]_{\\simplify[std]{{xu+xl}/2}}^x\\\\&=&1-\\simplify[std]{{2}/{p^2}}(\\var{xu}-x)^2 \\end{eqnarray*} \\]

\n

c)

\n

Probability

\n

Using the distribution function we have just found we have that:

\n

$P(\\var{lx} \\lt X \\lt \\var{ux}) = F_X(\\var{ux})-F_X(\\var{lx})$

\n

But $\\var{ux}$ is in the range between $\\var{(xl+xu)/2}$ and $\\var{xu}$ and the distribution function is given by:

\n

\\[F_X(x)=1-\\simplify[std]{{2}/{p^2}}(\\var{xu}-x)^2\\]

\n

Hence $F_X(\\var{ux})=1-\\simplify[std]{{2}/{p^2}}(\\var{xu}-\\var{ux})^2 = \\var{up}$ to 5 decimal places.

\n

Similarly, $\\var{lx}$ is in the range between $\\var{xl}$ and $\\var{(xl+xu)/2}$ and the distribution function is given by:

\n

\\[F_X(x)=\\simplify[std]{{2}/{p^2}}x^2\\]

\n

Hence $F_X(\\var{lx})=\\simplify[std]{{2}/{p^2}}(\\var{lx})^2 = \\var{lo}$ to 5 decimal places.

\n

Hence $P(\\var{lx} \\lt X \\lt \\var{ux}) = F_X(\\var{ux})-F_X(\\var{lx})=\\var{up}-\\var{lo}=\\var{up-lo}=\\var{ans}$ to 2 decimal places.

\n

Expectation.

\n

d) The expectation is given by  $\\displaystyle \\operatorname{E}[X]=\\int_{-\\infty}^{\\infty}xf_X(x)\\;dx$.

\n

As $f_X(x)=0$ for $x \\le \\var{xl}$ and $x \\ge \\var{xu}$ we see that:

\n

\\[\\begin{align}\\operatorname{E}[X]= \\int_{-\\infty}^{\\infty}xf_X(x)\\;dx &= \\int_{\\var{xl}}^{\\simplify[std]{{(xu+xl)}/2}}xf_X(x)\\;dx+ \\int_{\\simplify[std]{{(xu+xl)}/2}}^{\\var{xu}}xf_X(x)\\;dx\\\\&= c\\int_{\\var{xl}}^{\\simplify[std]{{(xu+xl)}/2}}x^2\\;dx+c\\int_{\\simplify[std]{{(xu+xl)}/2}}^{\\var{xu}}x({\\var{xu}-x)}\\;dx\\\\&=c \\left[ \\frac{x^3}{3} \\right]_{\\var{xl}}^{\\simplify[std]{{xu+xl}/2}} + c\\left[\\var{xu}\\frac{x^2}{2} - \\frac{x^3}{3}\\right]_{\\simplify[std]{{xu+xl}/2}}^{\\var{xu}}\\\\&=c\\times\\simplify[std]{{xu}^3/24}+c\\times \\simplify[std]{{xu}^3/12}\\\\&=\\simplify[std]{{xu}/2}\\end{align}\\]

\n

on remembering that $\\displaystyle c=\\simplify[std]{4/{p^2}}$

", "contributors": [{"name": "Newcastle University Mathematics and Statistics", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/697/"}]}]}], "contributors": [{"name": "Newcastle University Mathematics and Statistics", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/697/"}]}