// Numbas version: finer_feedback_settings {"name": "Maria's copy of 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}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"rulesets": {}, "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.
\nThe answer box for the third part plots the function which allows the student to check their answer against the graph before submitting.
\nThis particular example has a negative gradient.
", "licence": "Creative Commons Attribution 4.0 International"}, "variablesTest": {"maxRuns": 100, "condition": "\n"}, "functions": {"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-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;", "type": "html", "parameters": []}, "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-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;", "type": "html", "parameters": []}}, "tags": ["gradient", "graphs", "line equation", "negative gradient", "Straight Line", "straight line", "taxonomy", "y-intercept"], "ungrouped_variables": ["xa", "xb", "ya", "yb", "m", "c", "twos", "twos2"], "variable_groups": [], "parts": [{"variableReplacementStrategy": "originalfirst", "scripts": {}, "showFeedbackIcon": true, "gaps": [{"variableReplacementStrategy": "originalfirst", "minValue": "m", "mustBeReducedPC": 0, "allowFractions": false, "mustBeReduced": false, "unitTests": [], "showFeedbackIcon": true, "type": "numberentry", "notationStyles": ["plain", "en", "si-en"], "maxValue": "m", "correctAnswerStyle": "plain", "customMarkingAlgorithm": "", "correctAnswerFraction": false, "variableReplacements": [], "scripts": {}, "showCorrectAnswer": true, "marks": 1, "extendBaseMarkingAlgorithm": true}], "customMarkingAlgorithm": "", "prompt": "Calculate the gradient, $m$, of the line between these two points.
\n$ m=$ [[0]]
\n", "showCorrectAnswer": true, "variableReplacements": [], "type": "gapfill", "extendBaseMarkingAlgorithm": true, "marks": 0, "unitTests": []}, {"variableReplacementStrategy": "originalfirst", "scripts": {}, "showFeedbackIcon": true, "gaps": [{"variableReplacementStrategy": "originalfirst", "minValue": "c", "mustBeReducedPC": 0, "allowFractions": false, "mustBeReduced": false, "unitTests": [], "showFeedbackIcon": true, "type": "numberentry", "notationStyles": ["plain", "en", "si-en"], "maxValue": "c", "correctAnswerStyle": "plain", "customMarkingAlgorithm": "", "correctAnswerFraction": false, "variableReplacements": [], "scripts": {}, "showCorrectAnswer": true, "marks": 1, "extendBaseMarkingAlgorithm": true}], "customMarkingAlgorithm": "", "prompt": "Use this gradient and the points to calculate the $y$-intercept, $c$.
\n$c=$ [[0]]
", "showCorrectAnswer": true, "variableReplacements": [], "type": "gapfill", "extendBaseMarkingAlgorithm": true, "marks": 0, "unitTests": []}, {"variableReplacementStrategy": "originalfirst", "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"}}, "showFeedbackIcon": true, "gaps": [{"variableReplacementStrategy": "alwaysreplace", "scripts": {}, "showPreview": true, "failureRate": 1, "showFeedbackIcon": true, "showCorrectAnswer": true, "customMarkingAlgorithm": "", "checkVariableNames": true, "checkingAccuracy": 0.001, "vsetRangePoints": 5, "answer": "{m}*x+{c}", "expectedVariableNames": ["x"], "extendBaseMarkingAlgorithm": true, "variableReplacements": [], "checkingType": "absdiff", "type": "jme", "notallowed": {"message": "You must input your answer in the form y = mx +c where m and c are numbers.
", "strings": ["c", "m"], "showStrings": false, "partialCredit": 0}, "vsetRange": [0, 1], "marks": 1, "unitTests": []}], "customMarkingAlgorithm": "", "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]]
\nUse the graph to plot your answer and check that it goes through these points.
", "showCorrectAnswer": true, "variableReplacements": [], "type": "gapfill", "extendBaseMarkingAlgorithm": true, "marks": 0, "unitTests": []}], "extensions": ["jsxgraph"], "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()}
", "variables": {"yb": {"description": "", "definition": "ya-twos2", "group": "Ungrouped variables", "templateType": "anything", "name": "yb"}, "ya": {"description": "", "definition": "random(-5..5)", "group": "Ungrouped variables", "templateType": "anything", "name": "ya"}, "xa": {"description": "", "definition": "random(-5..2 except[0,-2,-4])", "group": "Ungrouped variables", "templateType": "anything", "name": "xa"}, "twos2": {"description": "", "definition": "random(2..4 except 3)", "group": "Ungrouped variables", "templateType": "anything", "name": "twos2"}, "m": {"description": "", "definition": "(ya-yb)/(xa-xb)", "group": "Ungrouped variables", "templateType": "anything", "name": "m"}, "c": {"description": "", "definition": "ya-m*xa", "group": "Ungrouped variables", "templateType": "anything", "name": "c"}, "xb": {"description": "", "definition": "xa+twos", "group": "Ungrouped variables", "templateType": "anything", "name": "xb"}, "twos": {"description": "", "definition": "random(2..4 except 3 )", "group": "Ungrouped variables", "templateType": "anything", "name": "twos"}}, "advice": "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.
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}
\\]
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{,} \\]
\nLet'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}
\\]
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}
\\]
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{.}\\]
\nThis is plotted below:
\n{correctPoints()}
", "name": "Maria's copy of Find the equation of a line through two points - negative gradient", "preamble": {"js": "", "css": ""}, "type": "question", "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/"}, {"name": "Maria Aneiros", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/3388/"}]}]}], "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/"}, {"name": "Maria Aneiros", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/3388/"}]}