// Numbas version: finer_feedback_settings {"name": "Charge on capacitor with plot", "extensions": ["jsxgraph"], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"name": "Charge on capacitor with plot", "tags": [], "metadata": {"description": "

This question gives the student the formula for the charge on a capacitor as a function of time then asks them to find the value of k, the exponential constant given other values and hence write out the formula for the given case. A custom function (in Extensions & scripts) extracts the student's formula and plots it on a JSXGraph object in the question. The student is then asked to evaluate the function at a given point using the plot or other methods. The value of the capacitor (Q_0), time (t) and charge at time t are randomised as is the value at which the formula is to be evaluated.

", "licence": "Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International"}, "statement": "", "advice": "

We have \\(Q_0=\\var{P_0}\\) \\(\\mu\\)F and \\(Q=\\var{pop}\\) \\(\\mu\\)F at \\(t = \\var{t}\\) milliseconds, hence:

\n

\\begin{align}\\var{pop}&=\\var{P_0}\\left(1-e^{-\\var{t}k}\\right)\\\\\\frac{\\var{pop}}{\\var{P_0}}&=\\left(1-e^{-\\var{t}k}\\right)\\\\e^{-\\var{t}k}&=1-\\frac{\\var{pop}}{\\var{P_0}}\\quad\\text{taking natural logs of both sides we have}\\\\-\\var{t}k&=\\ln\\left( 1-\\frac{\\var{pop}}{\\var{P_0}}\\right)\\\\k&=-\\frac{\\ln\\left(1-\\frac{\\var{pop}}{\\var{P_0}}\\right)}{\\var{t}}\\\\k&\\approx\\var{k} \\end{align}

\n

Hence the  formula for charge as a function of time is \\(Q(t)=\\var{P_0}\\left(1-e^{-\\var{k}t}\\right)\\)

\n

The graph of the charge vs time function will be:

\n

{sol_graph}

", "rulesets": {}, "extensions": ["jsxgraph"], "builtin_constants": {"e": true, "pi,\u03c0": true, "i": true}, "constants": [], "variables": {"pop": {"name": "pop", "group": "Ungrouped variables", "definition": "random(0.50*P_0..0.95*P_0 #20)", "description": "

Charge on capacitor at time t milliseconds, depends on value of P_0

", "templateType": "anything", "can_override": false}, "k": {"name": "k", "group": "Ungrouped variables", "definition": "precround(-ln(1-pop/P_0)/t,5)", "description": "

Value of k for given variables

", "templateType": "anything", "can_override": true}, "P_0": {"name": "P_0", "group": "Ungrouped variables", "definition": "random(300..1000 #100)", "description": "

Maximum charge on capacitor in micro Farads

", "templateType": "anything", "can_override": false}, "t": {"name": "t", "group": "Ungrouped variables", "definition": "random(50..500 #50)", "description": "

Time (in milliseconds) to achieve given charge (pop).

", "templateType": "anything", "can_override": false}, "sol_graph": {"name": "sol_graph", "group": "Ungrouped variables", "definition": "jessiecode(800,500,[-t/10,1.1*P_0,1.1*t,-0.1*P_0],\"\"\"\n line([0,{P_0}],[1,{P_0}])<>;\n text({t/2},{-0.06*P_0},\"Time (milliseconds)\");\n text({-t/15},{P_0/2},\"Charge (microF)\") <>;\n functiongraph('{fn}',0,{1.1*t}) <>;\n \"\"\",\n )", "description": "

JSXGraph plot of correct solution, used in Advice section.

", "templateType": "anything", "can_override": false}, "fn": {"name": "fn", "group": "Ungrouped variables", "definition": "'{P_0}*(1-exp(-{k}*x))'", "description": "

string representation of correct formula for charge on capacitor

", "templateType": "anything", "can_override": false}, "P_1": {"name": "P_1", "group": "Ungrouped variables", "definition": "random(100..pop-20 #20)", "description": "

Charge on capacitor at point to be evaluated in second part of question.

", "templateType": "anything", "can_override": false}}, "variablesTest": {"condition": "", "maxRuns": 100}, "ungrouped_variables": ["pop", "k", "P_0", "t", "sol_graph", "fn", "P_1"], "variable_groups": [], "functions": {"graph": {"parameters": [["p", "number"], ["time", "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: [-time/10,1.1*p,1.1*time,-0.1*p],\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 the static line based on the room temperature\nvar line1 = board.create('line',[[0,p],[1,p]],{fixed:true, strokeWidth:1});\nvar xlab = board.create('text',[time/2,-0.06*p,\"Time (milliseconds)\"]);\nvar ylab = board.create('text',[-time/15,p/2,\"Charge (microF)\"], {display: 'internal', rotate: 90});\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(t){\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: {t: new Numbas.jme.types.TNum(t)}}\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,0,1.1*time],\n {strokeColor:'black', strokeWidth: 3, 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[1].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": "

When a camera flash goes off, the batteries recharge the flash's capacitor to a charge \\(Q\\) given by  \\[Q=Q_0\\left(1-e^{-kt}\\right)\\] where \\(Q_0\\) is the maximum charge and \\(t\\) is measured in milliseconds. If the maximum charge  is \\(\\var{P_0}\\) \\(\\mu\\)F and at time \\(\\var{t}\\) milliseconds the charge  is \\(\\var{pop}\\) \\(\\mu\\)F, find the value of \\(k\\) accurate to 5 decimal places. Hence give the formula for the charge as a function of time. Show full working in your handwritten working.

\n

\\(k=\\;\\) [[0]] hence

\n

\\(Q(t)=\\;\\)[[1]] (note: to enter \\(e^{-kt}\\) type e^(-kt).)

\n

Graph of charge vs time will be shown below.

\n

{graph(P_0,t)}

\n

Using the above graph or otherwise, estimate the time taken for the capacitor to charge to \\(\\var{P_1}\\) \\(\\mu\\)F. (Note: your approximation should be given to the precision readable from the graph)

\n

\\(t\\approx\\)[[2]] milliseconds

\n

", "gaps": [{"type": "numberentry", "useCustomName": true, "customName": "k", "marks": "0.5", "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "minValue": "{k}", "maxValue": "{k}", "correctAnswerFraction": false, "allowFractions": false, "mustBeReduced": false, "mustBeReducedPC": 0, "displayAnswer": "", "precisionType": "dp", "precision": "5", "precisionPartialCredit": 0, "precisionMessage": "You have not given your answer to the correct precision.", "strictPrecision": false, "showPrecisionHint": false, "notationStyles": ["plain", "en", "si-en"], "correctAnswerStyle": "plain"}, {"type": "jme", "useCustomName": true, "customName": "Formula", "marks": "0.25", "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "answer": "{P_0}*(1-e^(-{k}t))", "showPreview": true, "checkingType": "absdiff", "checkingAccuracy": 0.001, "failureRate": 1, "vsetRangePoints": "10", "vsetRange": [0, "10"], "checkVariableNames": false, "singleLetterVariables": false, "allowUnknownFunctions": true, "implicitFunctionComposition": false, "caseSensitive": false, "valuegenerators": [{"name": "t", "value": ""}]}, {"type": "numberentry", "useCustomName": true, "customName": "time", "marks": "0.25", "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "minValue": "-0.9*ln(1-{P_1/P_0})/{k}", "maxValue": "-1.1*ln(1-{P_1/P_0})/{k}", "correctAnswerFraction": false, "allowFractions": false, "mustBeReduced": false, "mustBeReducedPC": 0, "displayAnswer": "-ln(1-{P_1/P_0})/{k}", "showFractionHint": true, "notationStyles": ["plain", "en", "si-en"], "correctAnswerStyle": "plain"}], "sortAnswers": false}], "partsMode": "all", "maxMarks": 0, "objectives": [], "penalties": [], "objectiveVisibility": "always", "penaltyVisibility": "always", "type": "question", "contributors": [{"name": "Don Shearman", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/680/"}, {"name": "Merryn Horrocks", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/4052/"}]}]}], "contributors": [{"name": "Don Shearman", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/680/"}, {"name": "Merryn Horrocks", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/4052/"}]}