// Numbas version: finer_feedback_settings {"name": "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": [{"name": "Straight lines: given two points find the equation", "tags": ["graph", "JSXgraph", "Jsxgraph", "jsxgraph", "linear equation", "straight lines", "y=mx+b"], "metadata": {"description": "
Identifying y=mx+b given two points
", "licence": "Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International"}, "statement": "", "advice": "", "rulesets": {}, "extensions": ["jsxgraph", "polynomials"], "builtin_constants": {"e": true, "pi,\u03c0": true, "i": true, "j": false}, "constants": [], "variables": {"const": {"name": "const", "group": "Ungrouped variables", "definition": "(x1*y0-x0*y1)/(x1-x0)\n", "description": "", "templateType": "anything", "can_override": false}, "m": {"name": "m", "group": "Ungrouped variables", "definition": "(y1-y0)/(x1-x0)", "description": "", "templateType": "anything", "can_override": false}, "y1": {"name": "y1", "group": "Ungrouped variables", "definition": "random(-10..10 except y0)", "description": "", "templateType": "anything", "can_override": false}, "y0": {"name": "y0", "group": "Ungrouped variables", "definition": "random(-10..10 except 0)", "description": "", "templateType": "anything", "can_override": false}, "x0": {"name": "x0", "group": "Ungrouped variables", "definition": "random(-10..10 except 0)", "description": "", "templateType": "anything", "can_override": false}, "x1": {"name": "x1", "group": "Ungrouped variables", "definition": "random(-10..10 except [x0,0])", "description": "", "templateType": "anything", "can_override": false}, "cf": {"name": "cf", "group": "Ungrouped variables", "definition": "gcd((y1-y0),(x1-x0))", "description": "", "templateType": "anything", "can_override": false}}, "variablesTest": {"condition": "", "maxRuns": 100}, "ungrouped_variables": ["x0", "y0", "x1", "y1", "m", "const", "cf"], "variable_groups": [], "functions": {"line_and_2points": {"parameters": [], "type": "html", "language": "javascript", "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;"}}, "preamble": {"js": "", "css": ""}, "parts": [{"type": "gapfill", "useCustomName": false, "customName": "", "marks": 0, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "prompt": "The gradient intercept form of the line that passes through the points $(\\var{x0},\\var{y0})$ and $(\\var{x1},\\var{y1})$ is
$y=$ [[0]]
{line_and_2points()}
\n", "stepsPenalty": "1", "steps": [{"type": "information", "useCustomName": false, "customName": "", "marks": 0, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "prompt": "There are a few ways to approach these questions:
\nIn particular, to find the equation of the line through $(\\var{x0},\\var{y0})$ and $(\\var{x1},\\var{y1})$. 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