// Numbas version: exam_results_page_options {"name": "Terry's copy of Straight lines: given two points find the equation", "extensions": ["jsxgraph", "polynomials"], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"type": "question", "question_groups": [{"pickingStrategy": "all-ordered", "questions": [], "pickQuestions": 0, "name": ""}], "variable_groups": [], "variables": {"x0": {"group": "Ungrouped variables", "name": "x0", "definition": "random(-10..10 except 0)", "templateType": "anything", "description": ""}, "y0": {"group": "Ungrouped variables", "name": "y0", "definition": "random(-10..10 except 0)", "templateType": "anything", "description": ""}, "y1": {"group": "Ungrouped variables", "name": "y1", "definition": "random(-10..10 except y0)", "templateType": "anything", "description": ""}, "x1": {"group": "Ungrouped variables", "name": "x1", "definition": "random(-10..10 except [x0,0])", "templateType": "anything", "description": ""}, "const": {"group": "Ungrouped variables", "name": "const", "definition": "(x1*y0-x0*y1)/(x1-x0)", "templateType": "anything", "description": ""}, "m": {"group": "Ungrouped variables", "name": "m", "definition": "(y1-y0)/(x1-x0)", "templateType": "anything", "description": ""}}, "showQuestionGroupNames": false, "preamble": {"js": "", "css": ""}, "tags": ["graph", "JSXgraph", "Jsxgraph", "jsxgraph", "linear equation", "straight lines", "y=mx+b"], "name": "Terry's copy of Straight lines: given two points find the equation", "rulesets": {}, "statement": "", "ungrouped_variables": ["x0", "y0", "x1", "y1", "m", "const"], "functions": {"line_and_2points": {"type": "html", "language": "javascript", "parameters": [], "definition": "\nvar div = Numbas.extensions.jsxgraph.makeBoard('600px','600px',{boundingBox:[-13,13,13,-13],grid:true,axis:false});\nvar board = div.board;\n\n// create the x-axis.\nvar xaxis = board.create('line',[[0,0],[1,0]], { strokeColor: 'black', fixed: true});\nvar xticks = board.create('ticks',[xaxis,2],{\n drawLabels: true,\n label: {offset: [-4, -10]},\n minorTicks: 0\n});\n\n// create the y-axis\nvar yaxis = board.create('line',[[0,0],[0,1]], { strokeColor: 'black', fixed: true });\nvar yticks = board.create('ticks',[yaxis,2],{\ndrawLabels: true,\nlabel: {offset: [-20, 0]},\nminorTicks: 0\n});\n\n\nx0 = Numbas.jme.unwrapValue(scope.variables.x0);\ny0 = Numbas.jme.unwrapValue(scope.variables.y0);\nx1 = Numbas.jme.unwrapValue(scope.variables.x1);\ny1 = Numbas.jme.unwrapValue(scope.variables.y1);\n\nboard.create('point',[x0,y0],{fixed:true});\nboard.create('point',[x1,y1],{fixed:true});\n\nvar studentExpression;\n\n// This function evaluates the student's expression at a given point `t`.\nfunction makestudentline(x){\n // Create a JME scope with the variable x set to the given value.\n var nscope = new Numbas.jme.Scope([\nNumbas.jme.builtinScope,\n{variables: {x: new Numbas.jme.types.TNum(x)}}\n ]);\n \n // If the student's input has been parsed, evaluate it\n if(studentExpression) {\ntry {\n var val = Numbas.jme.evaluate(studentExpression,nscope).value;\n return val;\n}\ncatch(e) {\n // If there was an error evaluating the student's expression\n // (wrong variables, or some other weirdness)\n // throw an error\n throw(e)\n}\n }\n // Otherwise, if the student's expression hasn't been parsed\n // (they haven't written anything, or they wrote bad syntax)\n // return 0\n else {\nreturn 0;\n }\n}\nvar studentline = board.create('functiongraph', \n [makestudentline,-13,13],\n {strokeColor:'#00ff00',strokeWidth:2, visible: false}\n );\n\n// This is where some voodoo happens.\n// Because the HTML for the question is inserted into the page after the function eqnline\n// is called, we need to wait until the 'question-html-attached' event is fired\n// to do the interaction with the student input box.\n// So:\n\n// When the question is inserted into the page\nquestion.signals.on('HTMLAttached',function(e) {\n \n // Create a Knockout.js observable\n ko.computed(function(){\n// Get the student's input string from part 0, gap 0.\nvar studentString = question.parts[0].gaps[0].display.studentAnswer();\n\n\n \n// Try to parse it as a JME expression\ntry {\nvar issue = /[A-W]|[YZ]|[\\^]/i.test(studentString);\n \n if(issue===false) \n {studentExpression = Numbas.jme.compile(studentString,scope)}\n else{studentExpression = null;\n studentline.hideElement()};///////////////////\n \n // If the student didn't write anything, compile returns null\n if(studentExpression === null)\nthrow(new Error('no expression'));\n\n \n // If everything worked, show the line and update it\n // (this calls makestudentline on a few points)\n studentline.showElement();\n studentline.updateCurve();\n}\ncatch(e) {\n // If something went wrong, hide the curve\n studentExpression = null;\n studentline.hideElement();\n}\n\nboard.update();\n });\n}); \n\nreturn div;"}}, "parts": [{"gaps": [{"vsetrangepoints": 5, "answer": "{y1-y0}/{x1-x0}*x+({x1*y0-x0*y1})/({x1-x0})", "variableReplacements": [], "vsetrange": [0, 1], "showCorrectAnswer": true, "checkingaccuracy": 0.001, "showpreview": true, "checkvariablenames": true, "checkingtype": "absdiff", "answersimplification": "all", "expectedvariablenames": ["x"], "marks": "2", "type": "jme", "scripts": {}, "variableReplacementStrategy": "originalfirst", "notallowed": {"message": "", "strings": ["="], "showStrings": false, "partialCredit": 0}}], "type": "gapfill", "steps": [{"type": "information", "variableReplacements": [], "marks": 0, "showCorrectAnswer": true, "scripts": {}, "variableReplacementStrategy": "originalfirst", "prompt": "

There are a few ways to approach these questions:

\n
    \n
  1. Use the two point formula for a line $y-y_1=\\frac{y_2-y_1}{x_2-x_1}(x-x_1)$. Or,

  2. \n
  3. Determine the gradient by $m=\\frac{\\text{rise}}{\\text{run}}$, or $m=\\frac{y_2-y_1}{x_2-x_1}$, and then use the one point gradient formula $y-y_1=m(x-x_1)$. Or,

  4. \n
  5. Determine the gradient by $m=\\frac{\\text{rise}}{\\text{run}}$, or $m=\\frac{y_2-y_1}{x_2-x_1}$. Pick a point and substitute it and the value for $m$ into the gradient intercept form of a line $y=mx+b$ to determine $b$. Now you have $m$ and $b$ so you can write the equation of the line in the form $y=mx+b$.
  6. \n
\n\n

\n
\n

\n\n

For example, suppose we had to find the equation of the line through $(2,3)$ and $(5,1)$. Let us call the first point $(x_1,y_1)$ and the second $(x_2,y_2)$. The following are examples of using the above approaches:

\n
    \n
  1. Substitute $(x_1,y_1)=(2,3)$ and $(x_2,y_2)=(5,1)$ into the equation $y-y_1=\\frac{y_2-y_1}{x_2-x_1}(x-x_1)$ to get $y-3=\\frac{1-3}{5-2}(x-2)$ (notice we leave $x$ and $y$ as variables). Simplifying the fraction we have $y-3=-\\frac{2}{3}(x-2)$. Expanding the brackets we have $y-3=-\\frac{2}{3}x+\\frac{4}{3}$. Making $y$ the subject gives $y=-\\frac{2}{3}x+\\frac{13}{3}$.

  2. \n
  3. Find the gradient, $m=\\frac{y_2-y_1}{x_2-x_1}=\\frac{1-3}{5-2}=-\\frac{2}{3}$. Substitute this and $(x_1,y_1)=(2,3)$ into the equation $y-y_1=m(x-x_1)$. This gives $y-3=-\\frac{2}{3}(x-2)$. Expanding the brackets we have $y-3=-\\frac{2}{3}x+\\frac{4}{3}$. Making $y$ the subject gives $y=-\\frac{2}{3}x+\\frac{13}{3}$.

  4. \n
  5. Find the gradient, $m=\\frac{y_2-y_1}{x_2-x_1}=\\frac{1-3}{5-2}=-\\frac{2}{3}$. Take a point, say $(2,3)$ as $(x,y)$ and substitute this and the gradient into the equation $y=mx+b$. This gives $3=-\\frac{2}{3}(2)+b$. Solving for $b$ gives $b=\\frac{13}{3}$. Therefore the equation of the line is $y=-\\frac{2}{3}x+\\frac{13}{3}$.
  6. \n
\n

\n

"}], "variableReplacements": [], "stepsPenalty": "1", "showCorrectAnswer": true, "scripts": {}, "marks": 0, "variableReplacementStrategy": "originalfirst", "prompt": "

The gradient intercept form of the line that passes through the points ({x0},{y0}) and ({x1},{y1}) is $y=$ [[0]]

\n

{line_and_2points()}

\n

"}], "variablesTest": {"maxRuns": 100, "condition": ""}, "metadata": {"description": "

Identifying y=mx+b given two points

", "licence": "Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International", "notes": ""}, "advice": "", "contributors": [{"name": "Ben Brawn", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/605/"}, {"name": "Terry Young", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/3130/"}]}]}], "contributors": [{"name": "Ben Brawn", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/605/"}, {"name": "Terry Young", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/3130/"}]}