// Numbas version: finer_feedback_settings {"name": "Find the equation of a line through two points - zero gradient", "extensions": ["jsxgraph"], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"tags": [], "statement": "

Find the equation of the straight line through the points  $A=(\\var{xa},\\var{ya})$ and  $B=(\\var{xb},\\var{yb})$ in the form $y = mx + c$.

\n

{plotPoints()}

", "variable_groups": [], "ungrouped_variables": ["xa", "yb", "ya", "xb", "m", "c"], "variables": {"yb": {"group": "Ungrouped variables", "description": "", "definition": "ya", "name": "yb", "templateType": "anything"}, "c": {"group": "Ungrouped variables", "description": "", "definition": "ya-m*xa", "name": "c", "templateType": "anything"}, "xb": {"group": "Ungrouped variables", "description": "", "definition": "xa+random([2,4,6])", "name": "xb", "templateType": "anything"}, "xa": {"group": "Ungrouped variables", "description": "", "definition": "random(-5..5 except 0)", "name": "xa", "templateType": "anything"}, "m": {"group": "Ungrouped variables", "description": "", "definition": "(ya-yb)/(xa-xb)", "name": "m", "templateType": "anything"}, "ya": {"group": "Ungrouped variables", "description": "", "definition": "random(-5..2 except 0)", "name": "ya", "templateType": "anything"}}, "variablesTest": {"condition": "\n", "maxRuns": 100}, "preamble": {"css": "", "js": ""}, "metadata": {"licence": "Creative Commons Attribution 4.0 International", "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 0 gradient.

"}, "parts": [{"variableReplacementStrategy": "originalfirst", "unitTests": [], "marks": 0, "customMarkingAlgorithm": "", "customName": "", "prompt": "

What is the gradient, $m$, of the line between these two points.

\n

 $ m=$ [[0]]

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

Calculate the $y$-intercept, $c$.

\n

$c=$ [[0]]

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

Combine the above results to find the straight line equation of the line running through these points in the form $y=mx+c$.

\n

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

", "showCorrectAnswer": true, "sortAnswers": false, "gaps": [{"variableReplacementStrategy": "originalfirst", "vsetRange": [0, 1], "notallowed": {"partialCredit": 0, "showStrings": false, "message": "

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

", "strings": ["c", "m"]}, "checkingType": "absdiff", "type": "jme", "showFeedbackIcon": true, "useCustomName": false, "customMarkingAlgorithm": "", "valuegenerators": [{"value": "", "name": "x"}], "variableReplacements": [], "scripts": {}, "checkVariableNames": true, "failureRate": 1, "marks": 1, "unitTests": [], "customName": "", "answer": "{m}*x+{c}", "showCorrectAnswer": true, "vsetRangePoints": 5, "checkingAccuracy": 0.001, "extendBaseMarkingAlgorithm": true, "showPreview": true}], "extendBaseMarkingAlgorithm": true, "type": "gapfill", "useCustomName": false, "showFeedbackIcon": true, "variableReplacements": [], "scripts": {"mark": {"order": "after", "script": "console.log(this.question.lines.c)\nthis.question.lines.l.setAttribute({strokeColor: this.credit==1 ? 'green' : 'red'});\nthis.question.lines.c.setAttribute({visible: this.credit==1 ? false : true});\n"}}}], "advice": "

a)

\n

The gradient is the ratio of vertical change ($y_2-y_1$) to horizontal change ($x_2-x_1$).
Since $y_2-y_1=0$, the gradient is $0$.

\n

b)

\n

Rearranging the equation $y=mx+c$ and using the coordinates of point A:

\n

\\begin{align}
c &= y_1-mx_1 \\\\
&= \\var{ya}-0 \\\\
&=\\var{ya}\\text{.}
\\end{align}

\n

\n

c)

\n

Substituting these values for $m$ and $c$ into $y=mx+c$,

\n

\\[ y=mx+c = \\simplify[!zeroTerm]{0+{c}} = \\var{c}\\text{.} \\]

\n

{correctPoints()}

\n

", "functions": {"correctPoints": {"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(xa-3,-2),math.max(ya+3,2),math.max(xb+3,2),math.min(yb-4,-2)],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", "parameters": []}, "plotPoints": {"language": "javascript", "definition": "\n//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(xa-3,-2),math.max(ya+3,2),math.max(xb+3,2),math.min(yb-4,-2)],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 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", "parameters": []}}, "rulesets": {}, "extensions": ["jsxgraph"], "name": "Find the equation of a line through two points - zero gradient", "type": "question", "contributors": [{"name": "Chris Graham", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/369/"}, {"name": "Vicky Hall", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/659/"}, {"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": "Xiaodan Leng", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/2146/"}]}]}], "contributors": [{"name": "Chris Graham", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/369/"}, {"name": "Vicky Hall", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/659/"}, {"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": "Xiaodan Leng", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/2146/"}]}