// Numbas version: exam_results_page_options {"name": "Maria's copy of Simon's copy of Equation of a line through two points - positive gradient", "extensions": ["jsxgraph"], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"extensions": ["jsxgraph"], "variables": {"yb": {"name": "yb", "description": "", "definition": "ya+random([2,4])", "group": "Ungrouped variables", "templateType": "anything"}, "xa": {"name": "xa", "description": "", "definition": "random(-4..-1)", "group": "Ungrouped variables", "templateType": "anything"}, "ya": {"name": "ya", "description": "", "definition": "random(-4..2)", "group": "Ungrouped variables", "templateType": "anything"}, "c": {"name": "c", "description": "", "definition": "ya-m*xa", "group": "Ungrouped variables", "templateType": "anything"}, "xb": {"name": "xb", "description": "", "definition": "xa+random([2,4] except -xa)", "group": "Ungrouped variables", "templateType": "anything"}, "m": {"name": "m", "description": "", "definition": "(ya-yb)/(xa-xb)", "group": "Ungrouped variables", "templateType": "anything"}}, "parts": [{"showCorrectAnswer": true, "unitTests": [], "gaps": [{"showFeedbackIcon": false, "showCorrectAnswer": true, "unitTests": [], "correctAnswerFraction": true, "variableReplacementStrategy": "originalfirst", "correctAnswerStyle": "plain", "notationStyles": ["plain", "en", "si-en"], "maxValue": "m", "type": "numberentry", "minValue": "m", "showFractionHint": true, "marks": 1, "useCustomName": false, "mustBeReduced": true, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "scripts": {}, "variableReplacements": [], "customName": "", "mustBeReducedPC": "50", "allowFractions": true}], "variableReplacementStrategy": "originalfirst", "showFeedbackIcon": true, "sortAnswers": false, "prompt": "

Calculate the gradient, $m$, of the straight line between these two points.

\n

$m=$ [[0]]

\n

", "marks": 0, "useCustomName": false, "type": "gapfill", "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "scripts": {}, "variableReplacements": [], "customName": ""}, {"showCorrectAnswer": true, "unitTests": [], "gaps": [{"showFeedbackIcon": false, "showCorrectAnswer": true, "unitTests": [], "correctAnswerFraction": false, "variableReplacementStrategy": "originalfirst", "correctAnswerStyle": "plain", "notationStyles": ["plain", "en", "si-en"], "maxValue": "c", "type": "numberentry", "minValue": "c", "showFractionHint": true, "marks": 1, "useCustomName": false, "mustBeReduced": false, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "scripts": {}, "variableReplacements": [], "customName": "", "mustBeReducedPC": 0, "allowFractions": false}], "variableReplacementStrategy": "originalfirst", "showFeedbackIcon": true, "sortAnswers": false, "prompt": "

Use this gradient and the coordinates of the points to calculate the $y$-intercept, $c$.

\n

$c=$ [[0]]

", "marks": 0, "useCustomName": false, "type": "gapfill", "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "scripts": {}, "variableReplacements": [], "customName": ""}, {"showCorrectAnswer": true, "unitTests": [], "gaps": [{"vsetRange": [0, 1], "showCorrectAnswer": true, "unitTests": [], "variableReplacementStrategy": "originalfirst", "marks": 1, "showPreview": true, "type": "jme", "checkingAccuracy": 0.001, "failureRate": 1, "variableReplacements": [], "customName": "", "valuegenerators": [{"value": "", "name": "x"}], "answer": "{m}*x+{c}", "answerSimplification": "fractionNumbers", "showFeedbackIcon": false, "notallowed": {"strings": ["c", "m"], "partialCredit": 0, "message": "

You must input your answer in the form y = mx +c where m and c are numbers.

", "showStrings": false}, "checkVariableNames": true, "useCustomName": false, "checkingType": "absdiff", "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "scripts": {}, "vsetRangePoints": 5}], "variableReplacementStrategy": "originalfirst", "showFeedbackIcon": true, "sortAnswers": false, "prompt": "

Give the equation of the straight line through these points in the form $y=mx+c$.

\n

$\\displaystyle y=$ [[0]]

", "marks": 0, "useCustomName": false, "type": "gapfill", "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "scripts": {"mark": {"order": "after", "script": "this.question.lines.l.setAttribute({strokeColor: this.credit==1 ? 'green' : 'red'});\nthis.question.lines.c.setAttribute({visible: this.credit==1});\n"}}, "variableReplacements": [], "customName": ""}], "variablesTest": {"maxRuns": 100, "condition": "\n"}, "rulesets": {}, "tags": [], "ungrouped_variables": ["xa", "xb", "ya", "yb", "m", "c"], "variable_groups": [], "metadata": {"description": "

Use two points on a line graph to calculate the gradient and $y$-intercept and hence the equation of the straight line running through both points.

\n

The answer box for the third part plots the function which allows the student to check their answer against the graph before submitting.

\n

This particular example has a positive gradient.

We find the equation of a straight line passing through two points by finding the gradient and the $y$-intercept of the line.

\n

#### (a)

\n

We can find the gradient ($m$) using the points $A = (x_1,y_1)=(\\var{xa},\\var{ya})$ and $B = (x_2,y_2)=(\\var{xb},\\var{yb})$.

\n

As the definition of gradient is the ratio of vertical change ($y_2-y_1$) to horizontal change ($x_2-x_1$).

\n

\\begin{align}
m &= \\frac{y_2-y_1}{x_2-x_1} \\\0.5em] &= \\frac{\\var{yb}-\\var{ya}}{\\var{xb}-\\var{xa}} \\\\[0.5em] &= \\frac{\\var{yb-ya}}{\\var{xb-xa}} \\\\[0.5em] &= \\var{m} \\end{align} \n \n #### (b) \n Rearranging the equation y=mx+c and substituting either of the points gives \n \\[c = y_1-mx_1 \\quad \\mathrm{or} \\quad c = y_2-mx_2 \\,\\text{.} \

\n

\n

For example, using point $A$:

\n

\\\begin{align} c &= y_1-mx_1 \\\\ &= \\var{ya}-\\var[fractionnumbers]{m}\\times\\var{xa} \\\\ & = \\simplify[fractionnumbers]{{ya-m*xa}}\\text{.} \\end{align} \

\n

\n

Similarly, we could have obtained the same value using point $B$:

\n

\\\begin{align} c &= y_2-mx_2 \\\\ &= \\var{yb}-\\var[fractionnumbers]{m}\\times\\var{xb} \\\\ & = \\simplify[fractionnumbers]{{yb-m*xb}}\\text{.} \\end{align} \

\n

\n

#### c)

\n

We can now substitute these values for $m$ and $c$ into $y=mx+c$  to get:

\n

\$y=\\simplify[!noLeadingMinus,fractionNumbers,unitFactor]{{m} x+ {c}}\\text{.}\$

\n

The green line drawn on the graph represents the above line equation.

\n

{correctPoints()}

", "name": "Maria's copy of Simon's copy of Equation of a line through two points - positive gradient", "statement": "

In this question we will identify the equation of the straight line passing through points  $A=(\\var{xa},\\var{ya})$ and  $B=(\\var{xb},\\var{yb})$ in the form $y = mx + c$.

\n

{plotPoints()}

", "preamble": {"js": "", "css": ""}, "functions": {"correctPoints": {"parameters": [], "language": "javascript", "definition": "//point coordinate variables\nvar xa = Numbas.jme.unwrapValue(scope.variables.xa);\nvar xb = Numbas.jme.unwrapValue(scope.variables.xb);\nvar ya = Numbas.jme.unwrapValue(scope.variables.ya);\nvar yb = Numbas.jme.unwrapValue(scope.variables.yb);\nvar m = Numbas.jme.unwrapValue(scope.variables.m);\nvar c = Numbas.jme.unwrapValue(scope.variables.c);\n\n//make board\nvar div = Numbas.extensions.jsxgraph.makeBoard('400px','400px',{boundingBox:[Math.min(-1,xa-2),Math.max(2,yb+2,c+1),Math.max(2,xb+2),Math.min(-1,ya-2,c-1)],grid: true});\nvar board = div.board;\nquestion.board = board;\n\n\n//points (with nice colors)\nvar a = board.create('point',[xa,ya],{name: 'A', size: 7, fillColor: 'blue' , strokeColor: 'lightblue' , highlightFillColor: 'lightblue', highlightStrokeColor: 'yellow', fixed: true, showInfobox: true});\nvar b = board.create('point',[xb,yb],{name: 'B', size: 7, fillColor: 'blue' , strokeColor: 'lightblue' , highlightFillColor: 'lightblue', highlightStrokeColor: 'yellow',fixed: true, showInfobox: true});\n\n\n//ans(was tree) is defined at the end and nscope looks important\n//but they're both variables\n\nvar correct_line = board.create('functiongraph',[function(x){ return m*x+c},-22,22], {strokeColor:\"green\",setLabelText:'mx+c',visible: true, strokeWidth: 4, highlightStrokeColor: 'green'} )\n\n\n\nquestion.signals.on('HTMLAttached',function(e) {\nko.computed(function(){\n//define ans as this \ncorrect_line.updateCurve();\nboard.update();\n});\n });\n\n\nreturn div;", "type": "html"}, "plotPoints": {"parameters": [], "language": "javascript", "definition": "//point coordinate variables\nvar xa = Numbas.jme.unwrapValue(scope.variables.xa);\nvar xb = Numbas.jme.unwrapValue(scope.variables.xb);\nvar ya = Numbas.jme.unwrapValue(scope.variables.ya);\nvar yb = Numbas.jme.unwrapValue(scope.variables.yb);\nvar m = Numbas.jme.unwrapValue(scope.variables.m);\nvar c = Numbas.jme.unwrapValue(scope.variables.c);\n\n//make board\nvar div = Numbas.extensions.jsxgraph.makeBoard('400px','400px',{boundingBox:[Math.min(-1,xa-2),Math.max(2,yb+2,c+1),Math.max(2,xb+2),Math.min(-1,ya-2,c-1)],grid: true});\nvar board = div.board;\nquestion.board = board;\n\n//points (with nice colors)\nvar a = board.create('point',[xa,ya],{name: 'A', size: 7, fillColor: 'blue' , strokeColor: 'lightblue' , highlightFillColor: 'lightblue', highlightStrokeColor: 'yellow', fixed: true, showInfobox: true});\nvar b = board.create('point',[xb,yb],{name: 'B', size: 7, fillColor: 'blue' , strokeColor: 'lightblue' , highlightFillColor: 'lightblue', highlightStrokeColor: 'yellow',fixed: true, showInfobox: true});\n\n\n//ans(was tree) is defined at the end and nscope looks important\n//but they're both variables\n var ans;\n var nscope = new Numbas.jme.Scope([scope,{variables:{x:new Numbas.jme.types.TNum(0)}}]);\n//this is the beating heart of whatever plots the function,\n//I've changed this from being curve to functiongraph\n var line = board.create('functiongraph',[function(x){\nif(ans) {\n try {\nnscope.variables.x.value = x;\n var val = Numbas.jme.evaluate(ans,nscope).value;\n return val;\n }\n catch(e) {\nreturn 13;\n }\n}\nelse\n return 13;\n },-12,12]\n , {strokeColor:\"blue\",strokeWidth: 4} );\n \nvar correct_line = board.create('functiongraph',[function(x){ return m*x+c},-22,22], {strokeColor:\"green\",setLabelText:'mx+c',visible: false, strokeWidth: 4, highlightStrokeColor: 'green'} )\n\nquestion.lines = {\n l:line, c:correct_line\n}\n\n question.signals.on('HTMLAttached',function(e) {\nko.computed(function(){\nvar expr = question.parts[2].gaps[0].display.studentAnswer();\n\n//define ans as this \ntry {\n ans = Numbas.jme.compile(expr,scope);\n}\ncatch(e) {\n ans = null;\n}\nline.updateCurve();\ncorrect_line.updateCurve();\nboard.update();\n});\n });\n\n\nreturn div;", "type": "html"}}, "type": "question", "contributors": [{"name": "Christian Lawson-Perfect", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/7/"}, {"name": "Angharad Thomas", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/315/"}, {"name": "Chris Graham", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/369/"}, {"name": "Bradley Bush", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/1521/"}, {"name": "Aiden McCall", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/1592/"}, {"name": "Simon Thomas", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/3148/"}, {"name": "Maria Aneiros", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/3388/"}]}]}], "contributors": [{"name": "Christian Lawson-Perfect", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/7/"}, {"name": "Angharad Thomas", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/315/"}, {"name": "Chris Graham", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/369/"}, {"name": "Bradley Bush", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/1521/"}, {"name": "Aiden McCall", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/1592/"}, {"name": "Simon Thomas", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/3148/"}, {"name": "Maria Aneiros", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/3388/"}]}