// Numbas version: exam_results_page_options {"timing": {"timedwarning": {"action": "none", "message": ""}, "allowPause": true, "timeout": {"action": "none", "message": ""}}, "showstudentname": true, "question_groups": [{"name": "Group", "pickQuestions": 1, "pickingStrategy": "all-ordered", "questions": [{"name": "Find the equation of a line through two points - negative gradient", "extensions": ["jsxgraph"], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "contributors": [{"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/"}], "variable_groups": [], "rulesets": {}, "functions": {"correctPoints": {"parameters": [], "language": "javascript", "type": "html", "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-4,-2),math.max(ya+4,2),math.max(xb+4,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;"}, "plotPoints": {"parameters": [], "language": "javascript", "type": "html", "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-4,-2),math.max(ya+4,2),math.max(xb+4,2),math.min(yb-4,-2)],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;"}}, "ungrouped_variables": ["xa", "xb", "ya", "yb", "m", "c", "twos", "twos2"], "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 negative gradient.

", "licence": "Creative Commons Attribution 4.0 International"}, "advice": "

a)

\n

We find the equation of a straight line passing through two points by finding the gradient and the $y$-intercept of the line.
We can find the gradient ($m$) using the points $A$ and $B$, $(x_1,y_1)=(\\var{xa},\\var{ya})$ and $(x_2,y_2)=(\\var{xb},\\var{yb})$ respectively.

\n

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} \\\\ 
&= \\frac{\\simplify[!collectNumbers]{{yb}-{ya}}}{\\simplify[!collectNumbers]{{xb}-{xa}}} \\\\ 
&= \\frac{\\simplify{{yb}-{ya}}}{\\simplify{{xb}-{xa}}} \\\\ 
&= \\simplify[simplifyFractions,unitDenominator]{({yb-ya})/({xb-xa})}\\text{.}
\\end{align}
\\]

\n

b)

\n

Rearranging the equation $y=mx+c$ and substituting either of the points gives two equations for the $y$-intercept $c$:

\n

\\[c = y_1-mx_1 \\quad \\mathrm{or} \\quad c = y_2-mx_2 \\,\\text{,} \\]

\n

Let's use point $B$:

\n

\\[
\\begin{align}
c &= y_2-mx_2 \\\\
&= \\var{ya}-(\\var{m}\\times\\var{xa}) \\\\
&= \\simplify{{ya-m*xa}}\\text{.}
\\end{align}
\\]

\n

We then check this against point $A$:

\n

\\[
\\begin{align}
y_1 &= mx_1 + c \\\\
&= \\simplify[fractionNumbers]{{m}{xb}+{c}} \\\\
&= \\simplify{{m}*{xb}+{c}}\\text{.}
\\end{align}
\\]

\n

c)

\n

Substituting our values for $m$ and $c$ into the equation for a straight line, $y=mx+c$, gives

\n

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

\n

This is plotted below:

\n

{correctPoints()}

", "statement": "

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

\n

{plotPoints()}

", "preamble": {"js": "", "css": ""}, "tags": ["gradient", "graphs", "line equation", "negative gradient", "Straight Line", "straight line", "taxonomy", "y-intercept"], "parts": [{"variableReplacementStrategy": "originalfirst", "sortAnswers": false, "scripts": {}, "variableReplacements": [], "type": "gapfill", "extendBaseMarkingAlgorithm": true, "prompt": "

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

\n

 $ m=$ [[0]]

\n

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

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

\n

$c=$ [[0]]

", "customName": "", "gaps": [{"extendBaseMarkingAlgorithm": true, "useCustomName": false, "correctAnswerStyle": "plain", "maxValue": "c", "customName": "", "showFractionHint": true, "variableReplacements": [], "unitTests": [], "customMarkingAlgorithm": "", "correctAnswerFraction": false, "mustBeReducedPC": 0, "variableReplacementStrategy": "originalfirst", "type": "numberentry", "marks": 1, "allowFractions": false, "minValue": "c", "mustBeReduced": false, "showCorrectAnswer": true, "showFeedbackIcon": true, "adaptiveMarkingPenalty": 0, "notationStyles": ["plain", "en", "si-en"], "scripts": {}}], "useCustomName": false, "adaptiveMarkingPenalty": 0, "unitTests": [], "showFeedbackIcon": true, "customMarkingAlgorithm": "", "marks": 0, "showCorrectAnswer": true}, {"variableReplacementStrategy": "originalfirst", "sortAnswers": false, "scripts": {"mark": {"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", "order": "after"}}, "variableReplacements": [], "type": "gapfill", "extendBaseMarkingAlgorithm": true, "prompt": "

Using your values for $m$ and $c$, write down the equation of the straight line which passes through the two points A and B, in the form $y = mx +c$ 

\n

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

\n

Use the graph to plot your answer and check that it goes through these points.

", "customName": "", "gaps": [{"answer": "{m}*x+{c}", "failureRate": 1, "extendBaseMarkingAlgorithm": true, "checkingAccuracy": 0.001, "valuegenerators": [{"name": "x", "value": ""}], "notallowed": {"message": "

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

", "showStrings": false, "partialCredit": 0, "strings": ["c", "m"]}, "checkingType": "absdiff", "unitTests": [], "customName": "", "variableReplacements": [], "vsetRange": [0, 1], "checkVariableNames": true, "customMarkingAlgorithm": "", "variableReplacementStrategy": "alwaysreplace", "type": "jme", "showPreview": true, "vsetRangePoints": 5, "useCustomName": false, "showCorrectAnswer": true, "showFeedbackIcon": true, "scripts": {}, "marks": 1, "adaptiveMarkingPenalty": 0}], "useCustomName": false, "adaptiveMarkingPenalty": 0, "unitTests": [], "showFeedbackIcon": true, "customMarkingAlgorithm": "", "marks": 0, "showCorrectAnswer": true}], "variables": {"c": {"name": "c", "description": "", "templateType": "anything", "group": "Ungrouped variables", "definition": "ya-m*xa"}, "yb": {"name": "yb", "description": "", "templateType": "anything", "group": "Ungrouped variables", "definition": "ya-twos2"}, "twos2": {"name": "twos2", "description": "", "templateType": "anything", "group": "Ungrouped variables", "definition": "random(2..4 except 3)"}, "m": {"name": "m", "description": "", "templateType": "anything", "group": "Ungrouped variables", "definition": "(ya-yb)/(xa-xb)"}, "xb": {"name": "xb", "description": "", "templateType": "anything", "group": "Ungrouped variables", "definition": "xa+twos"}, "twos": {"name": "twos", "description": "", "templateType": "anything", "group": "Ungrouped variables", "definition": "random(2..4 except 3 )"}, "ya": {"name": "ya", "description": "", "templateType": "anything", "group": "Ungrouped variables", "definition": "random(-5..5)"}, "xa": {"name": "xa", "description": "", "templateType": "anything", "group": "Ungrouped variables", "definition": "random(-5..2 except[0,-2,-4])"}}, "variablesTest": {"maxRuns": 100, "condition": "\n"}}, {"name": "Find the equation of a line through two points - positive gradient", "extensions": ["jsxgraph"], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "contributors": [{"name": "Christian Lawson-Perfect", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/7/"}, {"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/"}], "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()}

", "variables": {"m": {"name": "m", "description": "", "definition": "(ya-yb)/(xa-xb)", "templateType": "anything", "group": "Ungrouped variables"}, "yb": {"name": "yb", "description": "", "definition": "ya+random([2,4])", "templateType": "anything", "group": "Ungrouped variables"}, "xa": {"name": "xa", "description": "", "definition": "random(-4..-1)", "templateType": "anything", "group": "Ungrouped variables"}, "ya": {"name": "ya", "description": "", "definition": "random(-4..2)", "templateType": "anything", "group": "Ungrouped variables"}, "xb": {"name": "xb", "description": "", "definition": "xa+random([2,4] except -xa)", "templateType": "anything", "group": "Ungrouped variables"}, "c": {"name": "c", "description": "", "definition": "ya-m*xa", "templateType": "anything", "group": "Ungrouped variables"}}, "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.

", "licence": "Creative Commons Attribution 4.0 International"}, "tags": ["gradient", "graphs", "line equation", "Straight Line", "straight line", "taxonomy", "y-intercept"], "variablesTest": {"maxRuns": 100, "condition": "\n"}, "variable_groups": [], "ungrouped_variables": ["xa", "xb", "ya", "yb", "m", "c"], "advice": "

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$).
The equation for gradient is,

\n

\\begin{align}
m &= \\frac{y_2-y_1}{x_2-x_1} \\\\[0.5em]
&= \\frac{\\simplify[!collectNumbers]{{yb}-{ya}}}{\\simplify[!collectNumbers]{{xb}-{xa}}} \\\\[0.5em]
&= \\frac{\\simplify[]{{yb}-{ya}}}{\\simplify{{xb}-{xa}}} \\\\[0.5em]
&= \\simplify[simplifyFractions,unitDenominator]{({yb-ya})/({xb-xa})}\\text{.}
\\end{align}

\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

We can then also use this equation with the other point's coordinates to check our answer.

\n

Let's use point $A$ first:

\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

We then check this against point $B$:

\n

\\[
\\begin{align}
y_2 &= mx_2 + c \\\\[0.5em]
&= \\simplify[fractionNumbers]{{m}{xb}+{c}} \\\\[0.5em]
&= \\var[fractionnumbers]{m*xb+c}\\text{.}
\\end{align}
\\]

\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()}

", "preamble": {"css": "", "js": ""}, "parts": [{"showCorrectAnswer": true, "customMarkingAlgorithm": "", "prompt": "

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

\n

$m=$ [[0]]

\n

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

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

\n

$c=$ [[0]]

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

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

\n

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

\n

Use the graph to plot your answer and check that it goes through these points.

", "unitTests": [], "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"}}, "adaptiveMarkingPenalty": 0, "showFeedbackIcon": true, "type": "gapfill", "marks": 0, "gaps": [{"showPreview": true, "vsetRangePoints": 5, "scripts": {}, "unitTests": [], "checkingType": "absdiff", "vsetRange": [0, 1], "failureRate": 1, "answerSimplification": "fractionNumbers", "useCustomName": false, "answer": "{m}*x+{c}", "variableReplacements": [], "extendBaseMarkingAlgorithm": true, "showCorrectAnswer": true, "customMarkingAlgorithm": "", "notallowed": {"message": "

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

", "showStrings": false, "partialCredit": 0, "strings": ["c", "m"]}, "checkVariableNames": true, "checkingAccuracy": 0.001, "adaptiveMarkingPenalty": 0, "showFeedbackIcon": true, "type": "jme", "valuegenerators": [{"name": "x", "value": ""}], "customName": "", "marks": 1, "variableReplacementStrategy": "originalfirst"}], "useCustomName": false, "customName": "", "variableReplacements": [], "extendBaseMarkingAlgorithm": true, "variableReplacementStrategy": "originalfirst", "sortAnswers": false}], "functions": {"correctPoints": {"type": "html", "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;", "parameters": [], "language": "javascript"}, "plotPoints": {"type": "html", "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;", "parameters": [], "language": "javascript"}}, "rulesets": {}}, {"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}, "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/"}], "rulesets": {}, "functions": {"correctPoints": {"parameters": [], "language": "javascript", "type": "html", "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;"}, "plotPoints": {"parameters": [], "language": "javascript", "type": "html", "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;"}}, "ungrouped_variables": ["xa", "yb", "ya", "xb", "m", "c"], "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 0 gradient.

", "licence": "Creative Commons Attribution 4.0 International"}, "variable_groups": [], "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

", "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()}

", "preamble": {"js": "", "css": ""}, "tags": ["0 gradient", "gradient", "graphs", "line equation", "Straight Line", "straight line", "taxonomy", "y-intercept"], "parts": [{"variableReplacementStrategy": "originalfirst", "extendBaseMarkingAlgorithm": true, "variableReplacements": [], "type": "gapfill", "sortAnswers": false, "prompt": "

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

\n

 $ m=$ [[0]]

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

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

\n

$c=$ [[0]]

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

", "customName": "", "gaps": [{"failureRate": 1, "answer": "{m}*x+{c}", "extendBaseMarkingAlgorithm": true, "checkingAccuracy": 0.001, "valuegenerators": [{"name": "x", "value": ""}], "variableReplacements": [], "unitTests": [], "customName": "", "checkingType": "absdiff", "vsetRange": [0, 1], "showFeedbackIcon": true, "customMarkingAlgorithm": "", "variableReplacementStrategy": "originalfirst", "type": "jme", "showPreview": true, "vsetRangePoints": 5, "useCustomName": false, "showCorrectAnswer": true, "notallowed": {"message": "

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

", "strings": ["c", "m"], "partialCredit": 0, "showStrings": false}, "checkVariableNames": true, "marks": 1, "scripts": {}}], "useCustomName": false, "showCorrectAnswer": true, "unitTests": [], "showFeedbackIcon": true, "customMarkingAlgorithm": "", "marks": 0, "scripts": {"mark": {"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", "order": "after"}}}], "variables": {"yb": {"name": "yb", "description": "", "templateType": "anything", "group": "Ungrouped variables", "definition": "ya"}, "c": {"name": "c", "description": "", "templateType": "anything", "group": "Ungrouped variables", "definition": "ya-m*xa"}, "m": {"name": "m", "description": "", "templateType": "anything", "group": "Ungrouped variables", "definition": "(ya-yb)/(xa-xb)"}, "xb": {"name": "xb", "description": "", "templateType": "anything", "group": "Ungrouped variables", "definition": "xa+random([2,4,6])"}, "ya": {"name": "ya", "description": "", "templateType": "anything", "group": "Ungrouped variables", "definition": "random(-5..2 except 0)"}, "xa": {"name": "xa", "description": "", "templateType": "anything", "group": "Ungrouped variables", "definition": "random(-5..5 except 0)"}}, "variablesTest": {"maxRuns": 100, "condition": "\n"}}]}], "duration": 0, "name": "Find the equation of a line through two points", "navigation": {"preventleave": true, "allowregen": true, "browse": true, "showfrontpage": true, "showresultspage": "oncompletion", "reverse": true, "onleave": {"action": "none", "message": ""}}, "showQuestionGroupNames": false, "metadata": {"licence": "Creative Commons Attribution 4.0 International", "description": "

Questions asking you to find the equation of a line between two points, in Cartesian coordinates.

"}, "feedback": {"advicethreshold": 0, "showactualmark": true, "showtotalmark": true, "showanswerstate": true, "allowrevealanswer": true, "intro": "", "feedbackmessages": []}, "percentPass": 0, "type": "exam", "contributors": [{"name": "Angus Rosenburgh", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/2048/"}], "extensions": ["jsxgraph"], "custom_part_types": [], "resources": []}