// Numbas version: finer_feedback_settings {"name": "Tangent to curve with graph", "extensions": ["jsxgraph"], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"name": "Tangent to curve with graph", "tags": [], "metadata": {"description": "", "licence": "Creative Commons Attribution-NonCommercial-NoDerivs 4.0 International"}, "statement": "", "advice": "", "rulesets": {}, "extensions": ["jsxgraph"], "builtin_constants": {"e": true, "pi,\u03c0": true, "i": true, "j": false}, "constants": [], "variables": {"x": {"name": "x", "group": "Ungrouped variables", "definition": "random(-1,0,1)", "description": "", "templateType": "anything", "can_override": false}, "a": {"name": "a", "group": "Ungrouped variables", "definition": "random(-5..5 except 0)", "description": "", "templateType": "anything", "can_override": false}, "b": {"name": "b", "group": "Ungrouped variables", "definition": "random(-5..5 except 0)", "description": "", "templateType": "anything", "can_override": false}, "c": {"name": "c", "group": "Ungrouped variables", "definition": "random(-5..5 except 0)", "description": "", "templateType": "anything", "can_override": false}, "d": {"name": "d", "group": "Ungrouped variables", "definition": "random(-5..5)", "description": "", "templateType": "anything", "can_override": false}, "f": {"name": "f", "group": "Ungrouped variables", "definition": "random(5..9)", "description": "", "templateType": "anything", "can_override": false}, "g": {"name": "g", "group": "Ungrouped variables", "definition": "random(2..4)", "description": "", "templateType": "anything", "can_override": false}, "function": {"name": "function", "group": "Ungrouped variables", "definition": "substitute([\"a\":a,\"b\":b,\"c\":c,\"d\":d,\"f\":f,\"g\":g],\n expression(\"a*x^f+b*x^g+c*x+d\"))", "description": "", "templateType": "anything", "can_override": false}, "y_0": {"name": "y_0", "group": "Ungrouped variables", "definition": "eval(function,[\"x\":x])", "description": "", "templateType": "anything", "can_override": false}, "deriv": {"name": "deriv", "group": "Ungrouped variables", "definition": "diff(function,\"x\")", "description": "", "templateType": "anything", "can_override": false}, "grad": {"name": "grad", "group": "Ungrouped variables", "definition": "eval(deriv,[\"x\":x])", "description": "", "templateType": "anything", "can_override": false}}, "variablesTest": {"condition": "eval(function,[\"x\":1])<11 and eval(function,[\"x\":1])>-11 and eval(function,[\"x\":-1])<11 and eval(function,[\"x\":-1])>-11", "maxRuns": 100}, "ungrouped_variables": ["x", "a", "b", "c", "d", "f", "g", "function", "y_0", "deriv", "grad"], "variable_groups": [], "functions": {"graph": {"parameters": [["a", "number"], ["b", "number"], ["c", "number"], ["d", "number"], ["f", "number"], ["g", "number"]], "type": "html", "language": "javascript", "definition": "// This function creates the board and sets it up, then returns an\n// HTML div tag containing the board.\n \n\n\n// First, make the JSXGraph board.\n// The function provided by the JSXGraph extension wraps the board up in \n// a div tag so that it's easier to embed in the page.\nvar div = Numbas.extensions.jsxgraph.makeBoard('600px','400px',\n{boundingBox: [-2,15,2,-15],\n axis: true,\n showNavigation: false,\n grid: true\n});\n \n// div.board is the object created by JSXGraph, which you use to \n// manipulate elements\nvar board = div.board; \n\n\n\n// create graph of function from question\nvar line1 = board.create('functiongraph',[function(x) {return a*Math.pow(x,f)+b*Math.pow(x,g)+c*x+d;}, -2, 2],{fixed:true, strokeWidth:1});\n//var xlab = board.create('text',[a/2,-0.5,\"x\"]);\n//var ylab = board.create('text',[-0.5,2.5,\"y\"]);\n\n\n// Now we can do the clever stuff with the student's answer!\n// We'll add a curve to the board which is a plot of a function we provide.\n// That function will parse the student's input and evaluate it.\n\n// The variable `studentExpression` will store the parsed version of\n// the student's expression.\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,-2,2],\n {strokeColor:'red', 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// Try to parse it as a JME expression\ntry {\n studentExpression = Numbas.jme.compile(studentString,scope);\n \n // If the student didn't write anything, compile returns null\n if(studentExpression === null)\nthrow(new Error('no expression'));\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 curve \\[y=\\simplify{{a}*x^{f}+{b}*x^{g}+{c}*x+{d}}\\] is shown in the graph below.

\n

{graph(a,b,c,d,f,g)}

\n

Find the equation of the tangent to the above curve at the point where \\(x=\\var{x}\\). Show full working on your handwritten working.

\n

Your tangent line will be displayed in red on the graph above.

\n

Equation of tangent: \\(y=\\)[[0]]

\n

", "gaps": [{"type": "jme", "useCustomName": true, "customName": "Tangent", "marks": 1, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "answer": "{grad}*x-{grad*x}+{y_0}", "showPreview": true, "checkingType": "absdiff", "checkingAccuracy": 0.001, "failureRate": 1, "vsetRangePoints": 5, "vsetRange": [0, 1], "checkVariableNames": false, "singleLetterVariables": false, "allowUnknownFunctions": true, "implicitFunctionComposition": false, "caseSensitive": false, "valuegenerators": [{"name": "x", "value": ""}]}], "sortAnswers": false}], "partsMode": "all", "maxMarks": 0, "objectives": [], "penalties": [], "objectiveVisibility": "always", "penaltyVisibility": "always", "contributors": [{"name": "Don Shearman", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/680/"}], "resources": []}]}], "contributors": [{"name": "Don Shearman", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/680/"}]}