// Numbas version: finer_feedback_settings {"name": "Alex's copy of 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": [{"type": "question", "ungrouped_variables": ["a", "e1", "ux", "xl", "i1", "lo", "j1", "up", "exans", "p", "u", "t", "tol", "ans", "e2", "cval", "lx", "xu"], "rulesets": {"std": ["all", "fractionNumbers", "!collectNumbers", "!noLeadingMinus"]}, "preamble": {"css": "", "js": ""}, "functions": {}, "variable_groups": [], "metadata": {"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)$.
\nAlso find the expectation $\\displaystyle \\operatorname{E}[X]=\\int_{-\\infty}^{\\infty}xf_X(x)\\;dx$.
", "licence": "Creative Commons Attribution 4.0 International", "notes": "8/07/2012:
\nAdded tags.
\nChecked calculations, OK.
\nSet tolerance via new variable tol=0.01 for last question.
\n23/07/2012:
\nAdded description.
\n1/08/2012:
\nAdded tags.
\nIn the Advice section, moved \\Rightarrow to the beginning of the line instead of the end of the previous line.
\nQuestion appears to be working correctly.
\n21/12/2012:
\nChecked calculations, OK. Added tag tested1.
\nChecked rounding, OK. Added tag cr1.
"}, "variablesTest": {"condition": "", "maxRuns": 100}, "name": "Alex's copy of Construct a probability distribution function, then find CDF and expectation", "statement": "A random variable $X$ has a probability density function (PDF) given by:
", "showQuestionGroupNames": false, "parts": [{"type": "gapfill", "gaps": [{"type": "jme", "expectedvariablenames": [], "answersimplification": "std", "showCorrectAnswer": true, "vsetrangepoints": 5, "answer": "{4}/{p^2}", "vsetrange": [0, 1], "checkingaccuracy": 0.001, "showpreview": true, "notallowed": {"message": "input as a fraction and not a decimal
", "partialCredit": 0, "showStrings": false, "strings": ["."]}, "checkingtype": "absdiff", "scripts": {}, "checkvariablenames": false, "marks": 2}], "showCorrectAnswer": true, "scripts": {}, "prompt": "\n \n \n$f_X(x) = \\left \\{ \\begin{array}{l} \\phantom{{.}} \\\\ \\phantom{{.}} \\\\ \\phantom{{.}} \\\\\\phantom{{.}} \\\\ \\phantom{{.}} \\\\ \\phantom{{.}}\\end{array} \\right .$ | \n \n$0$ | \n \n$ x \\leq \\var{xl},$ | \n \n
\n \n | \n \n | |
$cx$ | \n \n$\\var{xl} \\lt x \\leq \\simplify[std]{{xu+xl}/2},$ | \n \n|
\n \n | \n \n | |
$c(\\var{xu}-x)$ | \n \n$\\simplify[std]{{xu+xl}/2} \\lt x \\leq \\var{xu},$ | \n \n|
\n \n | \n \n | |
$0$ | \n \n$x \\gt \\var{xu}.$ | \n \n
What value of $c$ makes $f_X(x)$ into the pdf of a distribution?
\n \n \n \nInput your answer here as a fraction and not as a decimal.
\n \n \n \n$c=\\;\\;$[[0]]
\n \n \n ", "marks": 0}, {"type": "gapfill", "gaps": [{"type": "jme", "expectedvariablenames": [], "showCorrectAnswer": true, "vsetrangepoints": 5, "answer": "0", "vsetrange": [0, 1], "checkingaccuracy": 0.001, "showpreview": true, "checkingtype": "absdiff", "scripts": {}, "checkvariablenames": false, "marks": 0.5}, {"type": "jme", "expectedvariablenames": [], "answersimplification": "std", "showCorrectAnswer": true, "vsetrangepoints": 5, "answer": "(({2} / {(p ^ 2)}) * ((x + ( - {xl})) ^ 2))", "vsetrange": [0, 1], "checkingaccuracy": 0.001, "showpreview": true, "notallowed": {"message": "input numbers as fractions or integers and not as decimals
", "partialCredit": 0, "showStrings": false, "strings": ["."]}, "checkingtype": "absdiff", "scripts": {}, "checkvariablenames": false, "marks": 1}, {"type": "jme", "expectedvariablenames": [], "answersimplification": "std", "showCorrectAnswer": true, "vsetrangepoints": 5, "answer": "(1 + ( - (({2} / {(p ^ 2)}) * ((x + ( - {xu})) ^ 2))))", "vsetrange": [0, 1], "checkingaccuracy": 0.001, "showpreview": true, "notallowed": {"message": "input numbers as fractions or integers and not as decimals
", "partialCredit": 0, "showStrings": false, "strings": ["."]}, "checkingtype": "absdiff", "scripts": {}, "checkvariablenames": false, "marks": 1}, {"type": "jme", "expectedvariablenames": [], "showCorrectAnswer": true, "vsetrangepoints": 5, "answer": "1", "vsetrange": [0, 1], "checkingaccuracy": 0.001, "showpreview": true, "checkingtype": "absdiff", "scripts": {}, "checkvariablenames": false, "marks": 0.5}], "showCorrectAnswer": true, "scripts": {}, "prompt": "\n \n \nGiven the value of $c$ found in the first part, determine and input the distribution function $F_X(x)$
\n \n \n \n$F_X(x) = \\left \\{ \\begin{array}{l} \\phantom{{.}} \\\\ \\phantom{{.}} \\\\ \\phantom{{.}} \\\\ \\phantom{{.}} \\\\ \\phantom{{.}} \\\\ \\phantom{{.}}\\\\ \\phantom{{.}}\\\\ \\phantom{{.}} \\end{array} \\right .$ | \n \n[[0]] | \n \n$x \\leq \\var{xl},$ | \n \n
\n \n | \n \n | |
[[1]] | \n \n$\\var{xl} \\lt x \\leq \\simplify[std]{{xu+xl}/2},$ | \n \n|
\n \n | \n \n | |
[[2]] | \n \n$\\simplify[std]{{xu+xl}/2} \\lt x \\leq \\var{xu},$ | \n \n|
\n \n | \n \n | |
[[3]] | \n \n$ x \\gt \\var{xu}.$ | \n \n
Input all numbers as fractions or integers in the above formulae.
\n \n \n ", "marks": 0}, {"type": "gapfill", "gaps": [{"type": "numberentry", "correctAnswerFraction": false, "showPrecisionHint": false, "maxValue": "ans+tol", "showCorrectAnswer": true, "scripts": {}, "minValue": "ans-tol", "allowFractions": false, "marks": 1}], "showCorrectAnswer": true, "scripts": {}, "prompt": "\n \n \nAlso, 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 ", "marks": 0}, {"type": "gapfill", "gaps": [{"type": "jme", "expectedvariablenames": [], "answersimplification": "all,fractionNumbers", "showCorrectAnswer": true, "vsetrangepoints": 5, "answer": "{xu}/2", "vsetrange": [0, 1], "checkingaccuracy": 0.001, "showpreview": true, "notallowed": {"message": "Input your answer as an integer or a fraction and not as a decimal.
", "partialCredit": 0, "showStrings": false, "strings": ["."]}, "checkingtype": "absdiff", "scripts": {}, "checkvariablenames": false, "marks": 1}], "showCorrectAnswer": true, "scripts": {}, "prompt": "Hence find the expectation
\n$\\displaystyle \\operatorname{E}[X]=\\int_{-\\infty}^{\\infty}xf_X(x)\\;dx$.
\n$\\operatorname{E}[X]\\;=\\;$[[0]]
\nInput your answer as an integer or a fraction.
", "marks": 0}], "question_groups": [{"pickQuestions": 0, "name": "", "pickingStrategy": "all-ordered", "questions": []}], "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"], "advice": "a)
Note that in order for $f_X(x)$ to be a pdf it must satisfy two important conditions:
1. $f_X(x) \\ge 0$ in the range $\\var{xl} \\le x \\le \\var{xu}$
\n2. 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.
We first check condition 2. and then check that condition 1. is satisfied.
\nHence \\[\\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*} \\]
But this has to equal $1$ and so \\[c=\\simplify[std]{4/{p^2}}\\]
\nHence with this value of $c$ we see that condition 2. is satisfied i.e.
\n\\[\\int_{-\\infty}^{\\infty}f_X(x)\\;dx=1\\]
\nCondition 1. is clearly satisfied as $c \\gt 0$.
\nb)
\nWe must have $F_X(x)=0,\\;\\;\\;x \\le \\var{xl},\\;\\;\\;\\textrm{and}\\;\\;\\;F_X(x)=1,\\;\\;\\;x \\ge \\var{xu}$
\nApart 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}]$
\n1. $x \\in [\\var{xl},\\simplify[std]{{xl+xu}/2}]$
\nWe 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*} \\]
\n2. $x \\in [\\simplify[std]{{xl+xu}/2},\\var{xu}]$
\nWe 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*} \\]
\nc)
\nUsing 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})$
\nBut $\\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\\]
\nHence $F_X(\\var{ux})=1-\\simplify[std]{{2}/{p^2}}(\\var{xu}-\\var{ux})^2 = \\var{up}$ to 5 decimal places.
\nSimilarly, $\\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\\]
\nHence $F_X(\\var{lx})=\\simplify[std]{{2}/{p^2}}(\\var{lx})^2 = \\var{lo}$ to 5 decimal places.
\nHence $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.
\nd) The expectation is given by $\\displaystyle \\operatorname{E}[X]=\\int_{-\\infty}^{\\infty}xf_X(x)\\;dx$.
\nAs $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}\\]
\non remembering that $\\displaystyle c=\\simplify[std]{4/{p^2}}$
", "variables": {"lx": {"templateType": "anything", "definition": "i1/2", "group": "Ungrouped variables", "description": "", "name": "lx"}, "j1": {"templateType": "anything", "definition": "round((u*(xu+1)+(100-u)*(2*xu-1))/100)", "group": "Ungrouped variables", "description": "", "name": "j1"}, "i1": {"templateType": "anything", "definition": "round((t+(100-t)*(xu-1))/100)", "group": "Ungrouped variables", "description": "", "name": "i1"}, "tol": {"templateType": "anything", "definition": "0.01", "group": "Ungrouped variables", "description": "", "name": "tol"}, "xu": {"templateType": "anything", "definition": "xl+random(4..15)", "group": "Ungrouped variables", "description": "", "name": "xu"}, "p": {"templateType": "anything", "definition": "(xu-xl)", "group": "Ungrouped variables", "description": "", "name": "p"}, "lo": {"templateType": "anything", "definition": "precround((2/p^2)*(lx-xl)^2,5)", "group": "Ungrouped variables", "description": "", "name": "lo"}, "a": {"templateType": "anything", "definition": "0", "group": "Ungrouped variables", "description": "", "name": "a"}, "ans": {"templateType": "anything", "definition": "precround(exans,2)", "group": "Ungrouped variables", "description": "", "name": "ans"}, "ux": {"templateType": "anything", "definition": "j1/2", "group": "Ungrouped variables", "description": "", "name": "ux"}, "exans": {"templateType": "anything", "definition": "up-lo", "group": "Ungrouped variables", "description": "", "name": "exans"}, "t": {"templateType": "anything", "definition": "random(0..100)", "group": "Ungrouped variables", "description": "", "name": "t"}, "xl": {"templateType": "anything", "definition": "0", "group": "Ungrouped variables", "description": "", "name": "xl"}, "e1": {"templateType": "anything", "definition": "4/p^2*(((xu+xl)/2)^3-xl^3)/3", "group": "Ungrouped variables", "description": "", "name": "e1"}, "e2": {"templateType": "anything", "definition": "4/p^2(((xu)^2/2*xu-xu^3/3)-((xu+xl)^2/2*xu-(xl+xu)^3/3))", "group": "Ungrouped variables", "description": "", "name": "e2"}, "up": {"templateType": "anything", "definition": "precround(1-(2/p^2)*(ux-xu)^2,5)", "group": "Ungrouped variables", "description": "", "name": "up"}, "u": {"templateType": "anything", "definition": "random(0..100)", "group": "Ungrouped variables", "description": "", "name": "u"}, "cval": {"templateType": "anything", "definition": "precround(4/p^2,4)", "group": "Ungrouped variables", "description": "", "name": "cval"}}, "contributors": [{"name": "Alex Van den Hof", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/1273/"}]}]}], "contributors": [{"name": "Alex Van den Hof", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/1273/"}]}