// Numbas version: finer_feedback_settings {"name": "Equation of a line through two points", "extensions": ["jsxgraph"], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"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()}

", "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"}, "type": "question", "rulesets": {}, "preamble": {"css": "", "js": ""}, "variables": {"yb": {"description": "", "name": "yb", "group": "Ungrouped variables", "definition": "ya+random([2,4])", "templateType": "anything"}, "ya": {"description": "", "name": "ya", "group": "Ungrouped variables", "definition": "random(-4..2)", "templateType": "anything"}, "m": {"description": "", "name": "m", "group": "Ungrouped variables", "definition": "(ya-yb)/(xa-xb)", "templateType": "anything"}, "c": {"description": "", "name": "c", "group": "Ungrouped variables", "definition": "ya-m*xa", "templateType": "anything"}, "xb": {"description": "", "name": "xb", "group": "Ungrouped variables", "definition": "xa+random([2,4] except -xa)", "templateType": "anything"}, "xa": {"description": "", "name": "xa", "group": "Ungrouped variables", "definition": "random(-4..-1)", "templateType": "anything"}}, "parts": [{"useCustomName": false, "gaps": [{"useCustomName": false, "customName": "", "showCorrectAnswer": true, "unitTests": [], "marks": 1, "customMarkingAlgorithm": "", "maxValue": "m", "scripts": {}, "notationStyles": ["plain", "en", "si-en"], "showFractionHint": true, "minValue": "m", "correctAnswerFraction": true, "showFeedbackIcon": true, "type": "numberentry", "variableReplacementStrategy": "originalfirst", "variableReplacements": [], "mustBeReduced": false, "extendBaseMarkingAlgorithm": true, "correctAnswerStyle": "plain", "mustBeReducedPC": 0, "allowFractions": true}], "showCorrectAnswer": true, "unitTests": [], "marks": 0, "sortAnswers": false, "showFeedbackIcon": true, "scripts": {}, "type": "gapfill", "variableReplacementStrategy": "originalfirst", "customName": "", "variableReplacements": [], "extendBaseMarkingAlgorithm": true, "customMarkingAlgorithm": "", "prompt": "

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

\n

$m=$ [[0]]

\n

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

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

\n

$c=$ [[0]]

"}], "functions": {"correctPoints": {"type": "html", "parameters": [], "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;", "language": "javascript"}, "plotPoints": {"type": "html", "parameters": [], "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;\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});\nvar correct_line = board.create('functiongraph',[function(x){ return m*x+c},-22,22], {strokeColor:\"blue\",setLabelText:'mx+c', strokeWidth: 4, highlightStrokeColor: 'green'} )\n\nreturn div;", "language": "javascript"}}, "variablesTest": {"maxRuns": 100, "condition": "\n"}, "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()}

", "extensions": ["jsxgraph"], "tags": [], "variable_groups": [], "ungrouped_variables": ["xa", "xb", "ya", "yb", "m", "c"], "name": "Equation of a line through two points", "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/"}, {"name": "Heather Driscoll", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/1703/"}, {"name": "Philip Charlton", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/3474/"}]}]}], "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/"}, {"name": "Heather Driscoll", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/1703/"}, {"name": "Philip Charlton", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/3474/"}]}