// Numbas version: exam_results_page_options {"name": "Straight lines: gradient intercept form of a line", "extensions": ["jsxgraph"], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"functions": {"eqnline": {"definition": "// This function creates the board and sets it up, then returns an\n// HTML div tag containing the board.\n \n// The line is described by the equation \n// y = a*x + b\n\n// This function takes as its parameters the coefficients a and b,\n// and the coordinates (x2,y2) of a point on the line.\n\n// First, make the JSXGraph board.\n// The function provided by the JSXGraph extension wraps the board up in \n// a div tag so that it's easier to embed in the page.\nvar div = Numbas.extensions.jsxgraph.makeBoard('400px','400px',\n{boundingBox: [-11,11,11,-11],\n axis: false,\n showNavigation: false,\n grid: true\n});\n \n// div.board is the object created by JSXGraph, which you use to \n// manipulate elements\nvar board = div.board; \n\n// create the x-axis.\nvar xaxis = board.create('line',[[0,0],[1,0]], { strokeColor: 'black', fixed: true});\nvar xticks = board.create('ticks',[xaxis,2],{\n drawLabels: true,\n label: {offset: [-4, -10]},\n minorTicks: 0\n});\n\n// create the y-axis\nvar yaxis = board.create('line',[[0,0],[0,1]], { strokeColor: 'black', fixed: true });\nvar yticks = board.create('ticks',[yaxis,2],{\ndrawLabels: true,\nlabel: {offset: [-20, 0]},\nminorTicks: 0\n});\n\n// create the static line based on the coefficients a and b\n//var line1 = board.create('line',[[0,b],[1,a+b]],{fixed:true, strokeWidth: 1});\n\n// mark the two given points - one on the y-axis, and one at (x2,y2)\n//var p1 = board.create('point',[0,b],{fixed:true, size:3, name: 'P_1', face: 'cross'});\n//var p2 = board.create('point',[x2,y2],{fixed:true, size:3, name: 'P_2', face: 'cross'});\n\n// Now we can do the clever stuff with the student's answer!\n// We'll add a curve to the board which is a plot of a function we provide.\n// That function will parse the student's input and evaluate it.\n\n// The variable `studentExpression` will store the parsed version of\n// the student's expression.\nvar studentExpression;\n\n// This function evaluates the student's expression at a given point `t`.\nfunction makestudentline(x){\n // Create a JME scope with the variable x set to the given value.\n var nscope = new Numbas.jme.Scope([\nNumbas.jme.builtinScope,\n{variables: {x: new Numbas.jme.types.TNum(x)}}\n ]);\n \n // If the student's input has been parsed, evaluate it\n if(studentExpression) {\ntry {\n var val = Numbas.jme.evaluate(studentExpression,nscope).value;\n return val;\n}\ncatch(e) {\n // If there was an error evaluating the student's expression\n // (wrong variables, or some other weirdness)\n // throw an error\n throw(e)\n}\n }\n // Otherwise, if the student's expression hasn't been parsed\n // (they haven't written anything, or they wrote bad syntax)\n // return 0\n else {\nreturn 0;\n }\n}\nvar studentline = board.create('functiongraph', \n [makestudentline,-11,11],\n {strokeColor:'#00ff00',strokeWidth:2, visible: false}\n );\n\n// This is where some voodoo happens.\n// Because the HTML for the question is inserted into the page after the function eqnline\n// is called, we need to wait until the 'question-html-attached' event is fired\n// to do the interaction with the student input box.\n// So:\n\n// When the question is inserted into the page\nquestion.signals.on('HTMLAttached',function(e) {\n \n // Create a Knockout.js observable\n ko.computed(function(){\n// Get the student's input string from part 0, gap 0.\nvar studentString = question.parts[2].gaps[0].display.studentAnswer();\n\n// Try to parse it as a JME expression\ntry {\n var issue = /[A-W]|[YZ]|[\\^]/i.test(studentString);\n if(issue===false) \n {studentExpression = Numbas.jme.compile(studentString,scope)}\n else{studentExpression = null;\n studentline.hideElement()};///////////////////\n \n \n // If the student didn't write anything, compile returns null\n if(studentExpression === null)\nthrow(new Error('no expression'));\n \n // If everything worked, show the line and update it\n // (this calls makestudentline on a few points)\n studentline.showElement();\n studentline.updateCurve();\n}\ncatch(e) {\n // If something went wrong, hide the curve\n studentExpression = null;\n studentline.hideElement();\n}\n\nboard.update();\n });\n}); \n\nreturn div;", "type": "html", "parameters": [], "language": "javascript"}}, "ungrouped_variables": ["rise", "run", "b", "rise1", "run1", "b1", "m2", "b2"], "name": "Straight lines: gradient intercept form of a line", "tags": ["gradient", "intercept", "linear equation", "Straight Line", "straight line", "y=mx+b"], "advice": "", "rulesets": {}, "parts": [{"stepsPenalty": "2", "prompt": "

The straight line with equation $y=\\simplify{{rise}/{run}* x+{b}}$ has a gradient of [[0]] and a $y$-intercept of [[1]].

\n

The gradient tells us that if we were on the line $y=\\simplify{{rise}/{run}* x+{b}}$ and we moved to the right {run} units then we would need to move [[2]] units upwards to get back on the line. 

\n

The $y$-intercept tells us where the line hits the $y$-axis, that is, the $y$ value when $x=$[[3]]. 

", "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "gaps": [{"allowFractions": true, "variableReplacements": [], "maxValue": "{rise}/{run}", "minValue": "{rise}/{run}", "variableReplacementStrategy": "originalfirst", "correctAnswerFraction": true, "showCorrectAnswer": true, "scripts": {}, "marks": 1, "type": "numberentry", "showPrecisionHint": false}, {"allowFractions": true, "variableReplacements": [], "maxValue": "{b}", "minValue": "{b}", "variableReplacementStrategy": "originalfirst", "correctAnswerFraction": true, "showCorrectAnswer": true, "scripts": {}, "marks": 1, "type": "numberentry", "showPrecisionHint": false}, {"allowFractions": false, "variableReplacements": [], "maxValue": "{rise}", "minValue": "{rise}", "variableReplacementStrategy": "originalfirst", "correctAnswerFraction": false, "showCorrectAnswer": true, "scripts": {}, "marks": 1, "type": "numberentry", "showPrecisionHint": false}, {"allowFractions": false, "variableReplacements": [], "maxValue": "0", "minValue": "0", "variableReplacementStrategy": "originalfirst", "correctAnswerFraction": false, "showCorrectAnswer": true, "scripts": {}, "marks": 1, "type": "numberentry", "showPrecisionHint": false}], "steps": [{"prompt": "

For $y=mx+b$, $m$ is the gradient and $b$ is the $y$-intercept.

\n

\n
\n

\n

The gradient (or slope of the line) is

\n\n

The $y$-intercept is the value of $y$ that the line crosses the $y$-axis at. Since the $y$-axis is the line that corresponds to $x=0$, the $y$-intercept is the $y$-value when $x=0$.

\n

\n
\n

\n

For example, given the equation $y=\\frac{2}{3}x-4$, we can see that the gradient is $\\frac{2}{3}$ and the $y$-intercept is $-4$. This constant gradient of $\\frac{2}{3}$ means that for a run of 3 we need a rise of 2 to stay on the line. Note it also means that say if we run across 6, we need to rise by 4, since $\\frac{2}{3}=\\frac{4}{6}$.

", "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "showCorrectAnswer": true, "scripts": {}, "marks": 0, "type": "information"}], "scripts": {}, "marks": 0, "showCorrectAnswer": true, "type": "gapfill"}, {"stepsPenalty": "1.5", "prompt": "

The straight line with equation $y=\\simplify{{rise1}/{run1}* x+{b1}}$ has a gradient of [[0]] and a $y$-intercept of [[1]].

\n

The gradient tells us that if we were on the line $y=\\simplify{{rise1}/{run1}* x+{b1}}$ and we moved to the right {2*run1} units then we would need to move [[2]] units downwards to get back on the line. 

\n

", "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "gaps": [{"allowFractions": true, "variableReplacements": [], "maxValue": "{rise1}/{run1}", "minValue": "{rise1}/{run1}", "variableReplacementStrategy": "originalfirst", "correctAnswerFraction": true, "showCorrectAnswer": true, "scripts": {}, "marks": 1, "type": "numberentry", "showPrecisionHint": false}, {"allowFractions": true, "variableReplacements": [], "maxValue": "{b1}", "minValue": "{b1}", "variableReplacementStrategy": "originalfirst", "correctAnswerFraction": true, "showCorrectAnswer": true, "scripts": {}, "marks": 1, "type": "numberentry", "showPrecisionHint": false}, {"allowFractions": false, "variableReplacements": [], "maxValue": "{-2*rise1}", "minValue": "{-2*rise1}", "variableReplacementStrategy": "originalfirst", "correctAnswerFraction": false, "showCorrectAnswer": true, "scripts": {}, "marks": 1, "type": "numberentry", "showPrecisionHint": false}], "steps": [{"prompt": "

For $y=mx+b$, $m$ is the gradient and $b$ is the $y$-intercept.

\n

\n
\n

\n

The gradient (or slope of the line) is

\n\n

The $y$-intercept is the value of $y$ that the line crosses the $y$-axis at. Since the $y$-axis is the line that corresponds to $x=0$, the $y$-intercept is the $y$-value when $x=0$.

\n

\n
\n

\n

For example, given the equation $y=\\frac{2}{3}x-4$, we can see that the gradient is $\\frac{2}{3}$ and the $y$-intercept is $-4$. This constant gradient of $\\frac{2}{3}$ means that for a run of 3 we need a rise of 2 to stay on the line. Note it also means that say if we run across 6, we need to rise by 4, since $\\frac{2}{3}=\\frac{4}{6}$.

", "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "showCorrectAnswer": true, "scripts": {}, "marks": 0, "type": "information"}], "scripts": {}, "marks": 0, "showCorrectAnswer": true, "type": "gapfill"}, {"stepsPenalty": "0.5", "prompt": "

If a straight line has a gradient of {m2} and a $y$-intercept of {b2} then its equation can be written as $y=$ [[0]].

\n

The following is the graph of the equation that you entered:

\n

{eqnline()}

", "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "gaps": [{"notallowed": {"message": "", "showStrings": false, "strings": ["sin", " cos", " exp", " "], "partialCredit": 0}, "variableReplacements": [], "expectedvariablenames": ["x"], "checkingaccuracy": 0.001, "type": "jme", "showpreview": true, "vsetrangepoints": 5, "variableReplacementStrategy": "originalfirst", "showCorrectAnswer": true, "answersimplification": "all", "scripts": {}, "answer": "{m2}*x+{b2}", "marks": 1, "checkvariablenames": true, "checkingtype": "absdiff", "vsetrange": [0, 1]}], "steps": [{"prompt": "

Recall the gradient intercept form of a straight line is $y=mx+b$ where $m$ is the gradient and $b$ is the $y$-intercept.

", "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "showCorrectAnswer": true, "scripts": {}, "marks": 0, "type": "information"}], "scripts": {}, "marks": 0, "showCorrectAnswer": true, "type": "gapfill"}], "statement": "", "variable_groups": [], "variablesTest": {"maxRuns": 100, "condition": ""}, "preamble": {"css": "", "js": ""}, "variables": {"run1": {"definition": "random(2..16)", "templateType": "anything", "group": "Ungrouped variables", "name": "run1", "description": ""}, "b": {"definition": "random(-12..12 except 0)", "templateType": "anything", "group": "Ungrouped variables", "name": "b", "description": ""}, "run": {"definition": "random(2..16)", "templateType": "anything", "group": "Ungrouped variables", "name": "run", "description": ""}, "rise": {"definition": "random(2..16)", "templateType": "anything", "group": "Ungrouped variables", "name": "rise", "description": ""}, "b1": {"definition": "random(-12..12 except 0)", "templateType": "anything", "group": "Ungrouped variables", "name": "b1", "description": ""}, "b2": {"definition": "random(-10..10)", "templateType": "anything", "group": "Ungrouped variables", "name": "b2", "description": ""}, "m2": {"definition": "random(-12..12 except 0)", "templateType": "anything", "group": "Ungrouped variables", "name": "m2", "description": ""}, "rise1": {"definition": "random(-16..-2)", "templateType": "anything", "group": "Ungrouped variables", "name": "rise1", "description": ""}}, "metadata": {"notes": "", "description": "

Identifying gradient and $y$-intercept from $y=mx+b$.

", "licence": "Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International"}, "type": "question", "showQuestionGroupNames": false, "question_groups": [{"name": "", "pickingStrategy": "all-ordered", "pickQuestions": 0, "questions": []}], "contributors": [{"name": "Ben Brawn", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/605/"}]}]}], "contributors": [{"name": "Ben Brawn", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/605/"}]}