// Numbas version: finer_feedback_settings {"name": "Tien Chern's orig copy of Custom marking - differentiate student's answer", "extensions": [], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"rulesets": {}, "variablesTest": {"condition": "", "maxRuns": 100}, "extensions": [], "metadata": {"licence": "Creative Commons Attribution 4.0 International", "description": ""}, "tags": [], "advice": "", "statement": "", "parts": [{"scripts": {}, "gaps": [{"checkingaccuracy": 0.001, "vsetrange": [0, 1], "showFeedbackIcon": true, "variableReplacements": [], "expectedvariablenames": [], "showCorrectAnswer": true, "checkvariablenames": false, "showpreview": true, "answer": "csc^2({a}x)+e^(x/{b})", "variableReplacementStrategy": "originalfirst", "checkingtype": "absdiff", "scripts": {"mark": {"script": "// get the student's answer\nvar integral = this.studentAnswer;\n\n// compute its derivative\nvar tree;\nvar derivative;\nvar derivative_tree;\ntry {\n tree = Numbas.jme.compile(integral);\n derivative_tree = Numbas.jme.differentiate(tree,'x');\n derivative = Numbas.jme.display.treeToJME(derivative_tree);\n derivative = Numbas.jme.display.simplifyExpression(derivative,'all',Numbas.jme.builtinScope);\n}\ncatch(e) {\n derivative = '';\n}\n\n// set the \"student's answer\" to the derivative\nthis.studentAnswer = derivative;\n\n// mark the JME part - the correct answer is the function which was to be integrated\nNumbas.parts.JMEPart.prototype.mark.apply(this);\n\n// set the student's answer back to what they typed\nthis.studentAnswer = integral;\n\nthis.markingFeedback = [];\n\n// If the derivative matches the original expression\nif(this.credit==1) { \n this.markingComment('Your answer is correct. Well done!');\n \n // check there's a constant of integration\n if(Numbas.jme.findvars(tree).length!=2) {\n this.multCredit(0.5,'You need to add a constant of integration, but otherwise this is correct.');\n }\n}\nelse {\n // Show the student what the derivative of their expression is\n var derivativeTeX = Numbas.jme.display.exprToLaTeX(derivative,[],Numbas.jme.builtinScope);\n this.markingComment('The derivative of your answer should be equal to the expression you were asked to integrate, i.e.: \\\\[ \\\\simplify{cos({a}x) + e^(x/{b})} \\\\] The derivative of your function is \\\\['+derivativeTeX+'\\\\]');\n}", "order": "instead"}}, "marks": 2, "type": "jme", "vsetrangepoints": 5}], "showFeedbackIcon": true, "variableReplacements": [], "showCorrectAnswer": true, "variableReplacementStrategy": "originalfirst", "marks": 0, "prompt": "
This part is marked by calculating the derivative of your answer and comparing it to the original expression.
\n$\\displaystyle{\\int \\simplify{csc^2({a}x) + e^(x/{b})} \\,\\mathrm{d}x = }$ [[0]]
", "type": "gapfill"}], "preamble": {"js": "//*************\n// differentiation\nvar jme = Numbas.jme;\nvar TNum = Numbas.jme.types.TNum;\n\nvar functionDerivatives = {\n 'cos': '-sin(x)',\n 'sin': 'cos(x)'\n};\nvar generalFunctionDerivative = jme.compile(\"f'(x)\");\nfor(var name in functionDerivatives) {\n functionDerivatives[name] = jme.compile(functionDerivatives[name]);\n}\nvar chainRule = jme.compile(\"x'*f'\")\n var opDerivatives = {\n '+': \"u'+v'\",\n '+u': \"+u'\",\n '-u': \"-u'\",\n '-': \"u'-v'\",\n '*': \"u'*v+u*v'\",\n \"/\": \"(v*u'-v'*u)/(v^2)\"\n }\n var powerRule = jme.compile(\"v*u'*u^(v-1)\");\nvar exponentialRule = jme.compile(\"ln(u)*v'*u^v\");\nfor(var name in opDerivatives) {\n opDerivatives[name] = jme.compile(opDerivatives[name]);\n}\n\nvar differentiate = jme.differentiate = function(tree,x) {\n var tok = tree.tok;\n \n switch(tok.type) {\n case 'number':\n return {tok: new TNum(0)};\n break;\n case 'name':\n return {tok: new TNum(tok.name==x ? 1 : 0)};\n case 'op':\n var l = differentiate(tree.args[0],x,1);\n if(tree.args.length>1)\n var r = differentiate(tree.args[1],x,1);\n var scope = {variables: {\"u\": tree.args[0], \"u'\": l, \"v\": tree.args[1], \"v'\": r}};\n if(tok.name=='^') {\n if(tree.args[1].tok.type=='number' || (tree.args[1].tok.type=='op' && tree.args[1].tok.name=='-u' && tree.args[1].args[0].tok.type=='number')) {\t// f(x)^n\n return jme.substituteTree(powerRule,scope);\n }\n else if(tree.args[0].tok.type=='number' || (tree.args[0].tok.type=='op' && tree.args[0].tok.name=='-u' && tree.args[0].args[0].tok.type=='number')) {\t// n^x\n return jme.substituteTree(exponentialRule,scope);\n }\n else {\n throw(new Numbas.Error('jme.differentiate.hard exponential'));\n }\n }\n return jme.substituteTree(opDerivatives[tok.name],scope);\n case 'function':\n var df = jme.substituteTree(tok.name in functionDerivatives ? functionDerivatives[tok.name] : generalFunctionDerivative,{variables:{x:tree.args[0], \"f'\": tok.name+\"'\"}});\n var dx = differentiate(tree.args[0],x);\n return jme.substituteTree(chainRule,{variables: {\"f'\": df, \"x'\": dx}});\n }\n}\n // end of differentiation code\n // ***************************\n \n question.signals.on('HTMLAttached',function() {\n var gap = question.parts[0].gaps[0];\n var omark = gap.mark;\n var add_constant_rule = new Numbas.jme.display.Rule('x+y',[]);\n });", "css": ""}, "variable_groups": [], "functions": {}, "name": "Tien Chern's orig copy of Custom marking - differentiate student's answer", "variables": {"b": {"name": "b", "templateType": "anything", "definition": "random(-10..10 except 0)", "description": "", "group": "Ungrouped variables"}, "a": {"name": "a", "templateType": "anything", "definition": "random(1..10)", "description": "", "group": "Ungrouped variables"}}, "ungrouped_variables": ["a", "b"], "type": "question", "contributors": [{"name": "Tien Chern Chia", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/1601/"}]}]}], "contributors": [{"name": "Tien Chern Chia", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/1601/"}]}