// Numbas version: exam_results_page_options {"name": "Ida's copy of Find the equation of a line through two points - positive gradient", "extensions": ["jsxgraph"], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"functions": {"correctPoints": {"type": "html", "language": "javascript", "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;"}, "plotPoints": {"type": "html", "language": "javascript", "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//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[1].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;"}}, "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()}

", "extensions": ["jsxgraph"], "preamble": {"js": "", "css": ""}, "parts": [{"showCorrectAnswer": true, "type": "gapfill", "variableReplacementStrategy": "originalfirst", "marks": 0, "prompt": "

Stigningstallet $a$ til en linje gjennom to punkter $(x_{1},y_{1}) og (x_{2},y_{2})$ er gitt ved

\n

$a=\\frac{y_{2}-y_{1}}{x_{2}-x_{1}}$. Finn stigningstallet til linja.

\n

$a=$ [[0]]

\n

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

Ei rett linje som går gjennom punktet $(x_{1},y_{1})$ og har stigningstallet $a$, er gitt ved likninga

\n

$y-y_{1}=a(x-x_{1})$.

\n

Finn likninga for linja. Skriv svaret på formen $y=ax+b$

\n

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

", "variableReplacements": [], "scripts": {"mark": {"script": "this.question.lines.l.setAttribute({strokeColor: this.credit==1 ? 'green' : 'red'});\nthis.question.lines.c.setAttribute({visible: this.credit==1});\n", "order": "after"}}, "showFeedbackIcon": true, "gaps": [{"showCorrectAnswer": true, "variableReplacementStrategy": "originalfirst", "checkvariablenames": true, "notallowed": {"partialCredit": 0, "strings": ["c", "m"], "showStrings": false, "message": "

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

"}, "answer": "{m}*x+{c}", "vsetrangepoints": 5, "vsetrange": [0, 1], "variableReplacements": [], "scripts": {}, "showFeedbackIcon": true, "checkingaccuracy": 0.001, "type": "jme", "expectedvariablenames": ["x"], "showpreview": true, "marks": 1, "answersimplification": "fractionNumbers", "checkingtype": "absdiff"}]}], "tags": [], "name": "Ida's copy of Find the equation of a line through two points - positive gradient", "variablesTest": {"condition": "\n", "maxRuns": 100}, "statement": "

Hvilken likning beskriver den rette linjen gjennom de to punktene med koordinatene $A=(\\var{xa},\\var{ya})$ og  $B=(\\var{xb},\\var{yb})$.

\n

{plotPoints()}

\n

", "rulesets": {}, "variable_groups": [], "variables": {"c": {"name": "c", "description": "", "templateType": "anything", "group": "Ungrouped variables", "definition": "ya-m*xa"}, "xa": {"name": "xa", "description": "", "templateType": "anything", "group": "Ungrouped variables", "definition": "random(-4..-1)"}, "yb": {"name": "yb", "description": "", "templateType": "anything", "group": "Ungrouped variables", "definition": "ya+random([2,4])"}, "m": {"name": "m", "description": "", "templateType": "anything", "group": "Ungrouped variables", "definition": "(ya-yb)/(xa-xb)"}, "ya": {"name": "ya", "description": "", "templateType": "anything", "group": "Ungrouped variables", "definition": "random(-4..2)"}, "xb": {"name": "xb", "description": "", "templateType": "anything", "group": "Ungrouped variables", "definition": "xa+random([2,4] except -xa)"}}, "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"}, "ungrouped_variables": ["xa", "xb", "ya", "yb", "m", "c"], "type": "question", "contributors": [{"name": "Ida Landg\u00e4rds", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/2336/"}]}]}], "contributors": [{"name": "Ida Landg\u00e4rds", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/2336/"}]}