// Numbas version: finer_feedback_settings {"name": "Normal Distribution", "extensions": ["stats", "jsxgraph"], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"functions": {"normaldist": {"definition": "//declaring some functions\n//the function that creates the curve\nfunction normal(x)\n{\n return (1/sigma*Math.sqrt(2*Math.PI))*Math.exp(-(x-mu)*(x-mu)/(2*sigma*sigma));\n}\n//the function to draw the curve\nfunction addCurve(board, func, atts) \n{\n var f = board.create('functiongraph', [func], atts);\n return f;\n}\n//the function to plot the curve\nfunction plot(func, atts) \n{\n if (atts==null) \n {\n return addCurve(board, func, {strokewidth:2});\n } \n else \n {\n return addCurve(board, func, atts);\n } \n}\n//generating random numbers\nfunction numgen()\n{\n var U1 = 0;\n var U2 = 0;\n var W = 0;\n var mult = 0;\n var X1 = 0;\n var X2 = 0;\n var call = 0;\n \n if (call == 1)\n {\n call = !call;\n return (mu + sigma * X2);\n }\n \n do\n {\n U1 = -1 + Math.random() * 2;\n U2 = -1 + Math.random() * 2;\n W = Math.pow (U1, 2) + Math.pow (U2, 2);\n }\n while (W >= 1 || W == 0);\n \n mult = Math.sqrt ((-2 * Math.log (W)) / W);\n X1 = U1 * mult;\n X2 = U2 * mult;\n \n call = !call;\n \n \n return (mu + sigma * X1);\n}\n\nfunction dr(p)\n{\n p.on('drag',function()\n {\n var num = 0;\n var mustr = '';\n var sigstr = '';\n if(p == ptmu)\n {\n p.moveTo([Math.min(Math.max(p.X(),-4),-2),4]);\n mu = p.X()+3;\n board.create('text',[-1.5,4, function(){ return (Math.round(mu*100)/100);}]);\n }\n else\n {\n p.moveTo([Math.min(Math.max(p.X(),-4),-2),4.5]);\n sigma = p.X()+4.5;\n board.create('text',[-1.5,4.5, function(){ return (Math.round(sigma*100)/100);}]);\n }\n for (j=0;j<50;j++) \n {\n //l[j]=numgen();\n l[j] = jStat.normal.sample(mu,sigma);\n board.removeObject(l2[j]);\n l2[j]=board.create('point',[l[j],0],{fixed:true,color:'red',withLabel:false});\n }\n //plot(normal);\n board.create('text',[4,4, function(){ return (Math.round(JXG.Math.Statistics.mean(l)*100)/100);}]);\n board.create('text',[4.5,4.5, function(){ return (Math.round(JXG.Math.Statistics.sd(l)*100)/100);}]);\n }\n )\n};\n\nfunction click(p)\n{\n p.on('up',function()\n {\n for (j=0;j<50;j++) \n {\n //l[j]=numgen();\n l[j] = jStat.normal.sample(mu,sigma);\n board.removeObject(l2[j]);\n l2[j]=board.create('point',[l[j],0],{fixed:true,color:'red',withLabel:false});\n }\n }\n )\n};\n\n//sorting out mu and sigma\nvar minx = -5;\nvar miny = -0.5;\nvar maxx = 5;\nvar maxy = 5;\n//creating the board\n var div = Numbas.extensions.jsxgraph.makeBoard('600px','600px',\n{boundingBox:[minx,maxy,maxx,miny],\n axis:true,\n showNavigation:false,\n grid:false});\nvar board = div.board; \n//var mu = board.create('slider',[[-1,1],[1,1],[-5,1,5]], {name:'&mu'});\n//var sigma = board.create('slider',[[-2,2],[0,2],[0.1,0.5,5]], {name:'sigma'});\nboard.create('text',[-4.05,4,'|'],{fixed:true,fontsize:30});\nboard.create('text',[-2.05,4,'|'],{fixed:true,fontsize:30});\nboard.create('text',[-4.05,4.5,'|'],{fixed:true,fontsize:30});\nboard.create('text',[-2.05,4.5,'|'],{fixed:true,fontsize:30});\nboard.create('line',[[-4,4],[-2,4]],{fixed:true,straightFirst:false,straightLast:false,color:'black'});\nboard.create('line',[[-4,4.5],[-2,4.5]],{fixed:true,straightFirst:false,straightLast:false,color:'black'});\nboard.create('text',[1,4,'The mean of the points is'],{fixed:true});\nboard.create('text',[1,4.5,'The standard deviation of the points is'],{fixed:true});\n\n\nvar mu = 0;\nvar sigma = 1.5;\n\nvar l = [];\nvar l2 = [];\n//for(i=0;i<50;i++){l.push(numgen())};\nfor(i=0;i<50;i++){l.push(jStat.normal.sample(mu,sigma))};\nfor (j=0;j<50;j++) {l2[j]=board.create('point',[l[j],0],{fixed:true,color:'red',withLabel:false})};\nplot(normal);\n\nvar ptmu = board.create('point',[-3,4],{name:'mu',face:'[]',showInfobox:false});\nvar ptsigma = board.create('point',[-3,4.5],{name:'sigma',face:'[]',showInfobox:false});\n\nclick(ptmu);\nclick(ptsigma);\ndr(ptmu);\ndr(ptsigma);\n\n\nreturn div;", "type": "html", "parameters": [], "language": "javascript"}}, "ungrouped_variables": ["r1", "r2", "a1", "b1", "n"], "name": "Normal Distribution", "tags": [], "advice": "
Explore the Normal distribution using the interactive diagram above.
", "rulesets": {}, "parts": [{"prompt": "{normaldist()}
\n", "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "showCorrectAnswer": true, "scripts": {}, "marks": 0, "type": "information"}], "extensions": ["stats", "jsxgraph"], "statement": "By moving the sliders for mu and sigma you may vary the mean and standard deviation of this Normal distribution.
", "variable_groups": [], "variablesTest": {"maxRuns": 100, "condition": ""}, "preamble": {"css": "", "js": ""}, "variables": {"a1": {"definition": "random(10..20)", "templateType": "anything", "group": "Ungrouped variables", "name": "a1", "description": ""}, "n": {"definition": "[random(1..10),random(1..10),random(1..10),random(1..10),random(1..10)]", "templateType": "anything", "group": "Ungrouped variables", "name": "n", "description": ""}, "r1": {"definition": "[random(0..6),random(1..7),random(4..10),random(7..13),random(12..18),random(4..20),random(16..22),random(19..25),random(17..23),random(13..19),random(8..14),random(3..9)]", "templateType": "anything", "group": "Ungrouped variables", "name": "r1", "description": ""}, "r2": {"definition": "map(round(a1+b1*x+random(-9..9)),x,r1)", "templateType": "anything", "group": "Ungrouped variables", "name": "r2", "description": ""}, "b1": {"definition": "random(0.25..0.45#0.05)", "templateType": "anything", "group": "Ungrouped variables", "name": "b1", "description": ""}}, "metadata": {"description": "Interactive Normal distribution where mean and standard deviation can be varied.
\nrebelmaths
", "licence": "Creative Commons Attribution 4.0 International"}, "type": "question", "showQuestionGroupNames": false, "question_groups": [{"name": "", "pickingStrategy": "all-ordered", "pickQuestions": 0, "questions": []}], "contributors": [{"name": "TEAME UCC", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/351/"}]}]}], "contributors": [{"name": "TEAME UCC", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/351/"}]}