// Numbas version: exam_results_page_options {"name": "Tien Chern's 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": [{"ungrouped_variables": ["a", "b"], "advice": "", "extensions": [], "functions": {}, "name": "Tien Chern's copy of Custom marking - differentiate student's answer", "preamble": {"css": "", "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 });"}, "variablesTest": {"maxRuns": 100, "condition": ""}, "metadata": {"description": "", "licence": "Creative Commons Attribution 4.0 International"}, "tags": [], "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"}}, "parts": [{"variableReplacementStrategy": "originalfirst", "marks": 0, "scripts": {}, "prompt": "

 

\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
", "gaps": [{"scripts": {"mark": {"script": "// get the student's answer\nvar integral = this.studentAnswer;\n\n// compute its derivative\nvar tree;\nvar derivative;\nvar derivative_tree;\nvar test;\n\n//try {\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//}\n//catch(e) {\n// derivative = '';\n//}\n\n// set the \"student's answer\" to the derivative\n//this.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\n//this.studentAnswer = integral;\n\nthis.markingFeedback = [];\n\n// If the derivative matches the original expression\nif(this.credit!=2) { \n this.markingComment('testing');\n \n // check there's a constant of integration\n if(Numbas.jme.findvars(tree).length==2) {\n //test = Numbas.jme.display.treeToJME(tree);\n //Numbas.jme.evaluate(test - C);\n this.markingComment('testing11');\n// this.multCredit(0.5,'You need to add a constant of integration, but otherwise this is correct.');\n }\n}\nelse{\n this.markingComment('Your answer is correct. Well done!');\n}", "order": "instead"}}, "showpreview": true, "checkingtype": "absdiff", "type": "jme", "answer": "-(1/{a})*cot({a}*x+{b})", "showFeedbackIcon": true, "variableReplacementStrategy": "originalfirst", "marks": 2, "vsetrange": [0, 1], "vsetrangepoints": 5, "showCorrectAnswer": true, "checkvariablenames": false, "expectedvariablenames": [], "checkingaccuracy": "c+0.001", "variableReplacements": []}], "type": "gapfill", "showCorrectAnswer": true, "variableReplacements": [], "showFeedbackIcon": true}], "statement": "", "variable_groups": [], "rulesets": {}, "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/"}]}