// Numbas version: finer_feedback_settings {"duration": 0, "navigation": {"allowregen": true, "showfrontpage": true, "preventleave": true, "reverse": true, "browse": true, "onleave": {"message": "", "action": "none"}, "showresultspage": "oncompletion"}, "timing": {"timeout": {"message": "", "action": "none"}, "timedwarning": {"message": "", "action": "none"}, "allowPause": true}, "metadata": {"description": "", "licence": "Creative Commons Attribution 4.0 International"}, "feedback": {"showanswerstate": true, "showtotalmark": true, "showactualmark": true, "feedbackmessages": [], "advicethreshold": 0, "intro": "", "allowrevealanswer": true, "enterreviewmodeimmediately": true, "showexpectedanswerswhen": "inreview", "showpartfeedbackmessageswhen": "always", "showactualmarkwhen": "always", "showtotalmarkwhen": "always", "showanswerstatewhen": "always", "showadvicewhen": "never"}, "showQuestionGroupNames": false, "question_groups": [{"pickingStrategy": "all-ordered", "pickQuestions": 1, "name": "Group", "questions": [{"name": "Interactive Newton-Raphson method", "extensions": ["jsxgraph"], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "contributors": [{"name": "Christian Lawson-Perfect", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/7/"}, {"name": "Chris Graham", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/369/"}], "tags": ["exponential functions", "iterative method", "Jsxgraph", "JSXgraph", "jsxgraph", "Newton-Raphson method", "newton-raphson method", "numerical methods", "numerical solution", "Solving equations", "solving equations", "Steps", "steps"], "metadata": {"description": "\n\t\t

Write down the Newton-Raphson formula for finding a numerical solution to the equation $e^{mx}+bx-a=0$. If $x_0=1$ find $x_1$.

\n\t\t

Included in the Advice of this question are:

\n\t\t

6 iterations of the method.

\n\t\t

Graph of the NR process using jsxgraph. Also user interaction allowing change of starting value and its effect on the process.

\n\t\t", "licence": "Creative Commons Attribution 4.0 International"}, "statement": "\n\t

Consider the following equation.

\n\t

\\[\\simplify[std]{e^({m}x)+{b}x-{a}=0}\\]

\n\t

Find the approximate solution in the range $0 \\le x \\le 1$ by using the Newton-Raphson method.

\n\t

The following diagram demonstrates the method.

\n\t

$x_0$ is the starting value, you can slide it along the x-axis to see the effect of changing it.

\n\t

\n\t

{test(m,b,a,maxy)}

\n\t

\n\t

\n\t

\n\t", "advice": "\n\t

a)

\n\t

Recall that the Newton-Raphson method is defined by:
\\[x_{n+1}=x_n-\\frac{g(x_n)}{g'(x_n)}\\]
where we would like to find the root of the equation $g(x)=0$

\n\t

In this question we have:
\\[\\simplify[std]{g(x) = Exp({m} * x) + {b} * x + { -a}} \\Rightarrow \\simplify[std]{g'(x) = {m}*Exp({m} * x) + {b}}\\]
Substituting these expressions into the formula we have:
\\[x_{n+1} =\\simplify[std]{ x_n -((Exp({m} * x_n) + {b} * x_n + { -a}) / ({m} * Exp({m} * x _n) + {b}))}\\]

\n\t

which can be rearranged to give:
\\[x _{n + 1} = \\simplify[std]{(({m} * x_n -1) * Exp({m} * x _n) + {a}) / ({m} * Exp({m} * x _n) + {b})}\\]

\n\t

(In your answers you would input $x$ rather than $x_n$.)

\n\t

In the following let $\\displaystyle f(x)=\\simplify[std]{ (({m} * x -1) * Exp({m} * x ) + {a}) / ({m} * Exp({m} * x ) + {b})}$

\n\t

b)

\n\t

If $x_0=2$ then $x_1$ is simply given by:
\\[\\simplify[std]{x_1 = (({2*m} -1) * Exp({2*m}) + {a}) / ({m} * Exp({2*m}) + {b})}\\]

\n\t

which to 4 decimal places is: $\\;\\;x_1= \\var{ans}$

\n\t

We find on running the iteration that the first six values are:

\n\t

\\[\\begin{align}x_1&=f(x_0)=f(2)&=\\var{results[1]}\\\\x_2&=f(x_1)=f(\\var{results[1]})&=\\var{results[2]}\\\\x_3&=f(x_2)=f(\\var{results[2]})&=\\var{results[3]}\\\\x_4&=f(x_3)=f(\\var{results[3]})&=\\var{results[4]}\\\\x_5&=f(x_4)=f(\\var{results[4]})&=\\var{results[5]}\\\\x_6&=f(x_5)=f(\\var{results[5]})&=\\var{results[6]}\\end{align}\\]

\n\t

So the solution to the equation to four decimal places for $0 \\le x \\le 1$ is $x=\\var{precround(ans1,4)}$

\n\t

Here we see the graph of $\\simplify{e^({m}*x)+{b}*x-{a}}$ and the first four successive approximations to the root:

\n\t

{test(m,b,a,maxy)}

\n\t

\n\t

Note that you can slide the first approximation $x_0$ along the x-axis to see the effect of changing the starting value.

\n\t", "rulesets": {"std": ["all", "!collectNumbers", "!noLeadingMinus"]}, "variables": {"tol": {"name": "tol", "group": "Ungrouped variables", "definition": "0", "description": "", "templateType": "anything"}, "ans": {"name": "ans", "group": "Ungrouped variables", "definition": "precround(tans,4)", "description": "", "templateType": "anything"}, "ans1": {"name": "ans1", "group": "Ungrouped variables", "definition": "precround(results[6],4)", "description": "", "templateType": "anything"}, "maxy": {"name": "maxy", "group": "Ungrouped variables", "definition": "ceil(e^(2*m)+2*b-a)+5", "description": "", "templateType": "anything"}, "m": {"name": "m", "group": "Ungrouped variables", "definition": "random(1.5..2#0.1)", "description": "", "templateType": "anything"}, "tans": {"name": "tans", "group": "Ungrouped variables", "definition": "((2*m-1)*exp(2*m)+a)/(m*exp(2*m)+b)", "description": "", "templateType": "anything"}, "a": {"name": "a", "group": "Ungrouped variables", "definition": "random(8..15)", "description": "", "templateType": "anything"}, "b": {"name": "b", "group": "Ungrouped variables", "definition": "random((a+1)..9)", "description": "", "templateType": "anything"}, "results": {"name": "results", "group": "Ungrouped variables", "definition": "nr(m,b,a,2,10,[])", "description": "", "templateType": "anything"}}, "variablesTest": {"condition": "", "maxRuns": 100}, "ungrouped_variables": ["a", "m", "ans1", "ans", "b", "tol", "tans", "maxy", "results"], "variable_groups": [], "functions": {"test": {"parameters": [["m", "number"], ["b", "number"], ["a", "number"], ["maxy", "number"]], "type": "html", "language": "javascript", "definition": "\n\t\t\tvar div = Numbas.extensions.jsxgraph.makeBoard('600px','400px', {boundingbox:[0,maxy,3,-30], axis:false});\n\t\t\t var brd=div.board;\n\t\t\t // Initial function term\n\t\t\t var term = function(x) { return Math.exp(m*x)+b*x-a; };\n\t\t\t var graph = function(x) { return term(x); };\n\t\t\t // Recursion depth\n\t\t\t var steps = 4;\n\t\t\t // Start value\n\t\t\t var s = 2;\n\t\t\t \n\t\t\t //for (i = 0; i < steps; i++) {\n\t\t\t //document.write('x' + i + ' = ');\n\t\t\t //}\n\t\t\t \n\t\t\t var i;\n\t\t\t var ax = brd.create('axis', [[0,0], [1,0]], {strokeColor: 'black'});\n\t\t\t var ay = brd.create('axis', [[0,0], [0,1]], {strokeColor: 'black'});\n\t\t\t \n\t\t\t var g = brd.create('functiongraph', [function(x){return graph(x);}],{strokeWidth: 2, dash:0});\n\t\t\t var x = brd.create('glider',[s,0,ax], {name: 'x_{0}', strokeColor: 'magenta', fillColor: 'yellow'});\n\t\t\t \n\t\t\t newton(x, steps, brd);\t\n\t\t\t \n\t\t\t //function xval() {\n\t\t\t //for (i = 0; i < steps; i++)\n\t\t\t //document.getElementById('xv' + i).innerHTML = (brd.select('x_{' + i + '}').X()).toFixed(14);\n\t\t\t //}\n\t\t\t \n\t\t\t //brd.addHook(xval);\n\t\t\t \n\t\t\t function newton(p, i, board) {\t\n\t\t\t board.suspendUpdate();\t\n\t\t\t if(i>0) {\n\t\t\t var f = board.create('glider',[function(){return p.X();}, function(){return graph(p.X())},g], {name: '', style: 3, strokeColor: 'green', fillColor: 'yellow'});\n\t\t\t var l = board.create('line', [p,f],{strokeWidth: 0.5, dash: 1, straightFirst: false, straightLast: false, strokeColor: 'black'});\n\t\t\t var t = board.create('tangent',[f],{strokeWidth: 0.5, strokeColor: '#0080c0', dash: 0});\n\t\t\t var x = board.create('intersection',[ax,t,0],{name: 'x_{'+(steps-i+1) + '}', style: 4, strokeColor: 'magenta', fillColor: 'yellow'});\n\t\t\t newton(x,--i, board);\n\t\t\t }\n\t\t\t board.unsuspendUpdate(); \n\t\t\t \n\t\t\t \n\t\t\t }\t\n\t\t\t return div;\n\t\t\t"}, "nr": {"parameters": [["m", "number"], ["b", "number"], ["a", "number"], ["c", "number"], ["n", "number"], ["l", "list"]], "type": "list", "language": "jme", "definition": "if(n=5,l+[fun(m,b,a,c)]+[fun(m,b,a,fun(m,b,a,c))],nr(m,b,a,fun(m,b,a,c),n-1,l+[c]))"}, "fun": {"parameters": [["m", "number"], ["b", "number"], ["a", "number"], ["c", "number"]], "type": "number", "language": "jme", "definition": "((m*c-1)*e^(m*c)+a)/(m*e^(m*c)+b)"}, "funfornr": {"parameters": [], "type": "html", "language": "javascript", "definition": "\n\t\t\tvar div = Numbas.extensions.jsxgraph.makeBoard('600px','200px',{boundingBox:[0,10,1,-8],grid:false});\n\t\t\t var board = div.board;\n\t\t\t var m = Numbas.jme.unwrapValue(scope.variables.m);\n\t\t\t var be = Numbas.jme.unwrapValue(scope.variables.b);\n\t\t\t var al = Numbas.jme.unwrapValue(scope.variables.a);\n\t\t\t var ans = Numbas.jme.unwrapValue(scope.variables.ans1)\n\t\t\t var a = board.create('point',[ans,0],'$A$');\n\t\t\t \n\t\t\t var graph = board.create('functiongraph',function(x){return Math.exp(m*x)+be*x-al});\n\t\t\t \n\t\t\t return div;\n\t\t\t \n\t\t\t"}}, "preamble": {"js": "", "css": ""}, "parts": [{"type": "gapfill", "useCustomName": false, "customName": "", "marks": 0, "showCorrectAnswer": true, "showFeedbackIcon": true, "scripts": {}, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "adaptiveMarkingPenalty": 0, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "prompt": "\n\t\t\t

This equation has a root in the range $0 \\lt x \\lt 1$.

\n\t\t\t

Using the Newton-Raphson formula, if $x_n$ is the $n$th estimate for this root, show that the next estimate can be written in the form \\[x_{n+1}= \\frac{p(x_n)}{g'(x_n)}\\]
Enter $p(x_n)$ and $g'(x_n)$ in the boxes below.

\n\t\t\t

Please note that if you enter a function of the form $xe^{ax}$, then you must input it as $x*e^{ax}$.

\n\t\t\t

$p(x_n)=\\;\\;$[[0]] In your answer use $x$ instead of $x_n$.

\n\t\t\t

$g'(x_n)=\\;\\;$[[1]] In your answer use $x$ instead of $x_n$.

\n\t\t\t

If you have forgotten the Newton-Raphson formula you can click on Steps to see it. You will not lose any marks in doing so.

\n\t\t\t \n\t\t\t", "stepsPenalty": 0, "steps": [{"type": "jme", "useCustomName": false, "customName": "", "marks": 0, "showCorrectAnswer": true, "showFeedbackIcon": true, "scripts": {}, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "adaptiveMarkingPenalty": 0, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "prompt": "

Recall that the Newton-Raphson method is defined by:
\\[x_{n+1}=x_n-\\frac{g(x_n)}{g'(x_n)}\\]
where we would like to find the root of the equation $g(x)=0$

", "answer": "", "showPreview": true, "checkingType": "absdiff", "checkingAccuracy": 0.001, "failureRate": 1, "vsetRangePoints": 5, "vsetRange": [0, 1], "checkVariableNames": false, "valuegenerators": []}], "gaps": [{"type": "jme", "useCustomName": false, "customName": "", "marks": 1, "showCorrectAnswer": true, "showFeedbackIcon": true, "scripts": {}, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "adaptiveMarkingPenalty": 0, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "answer": "(((({m} * x) -1) * Exp(({m} * x))) + {a})", "answerSimplification": "std", "showPreview": true, "checkingType": "absdiff", "checkingAccuracy": 0.0001, "failureRate": 1, "vsetRangePoints": 5, "vsetRange": [1, 1.5], "checkVariableNames": false, "valuegenerators": [{"name": "x", "value": ""}]}, {"type": "jme", "useCustomName": false, "customName": "", "marks": 1, "showCorrectAnswer": true, "showFeedbackIcon": true, "scripts": {}, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "adaptiveMarkingPenalty": 0, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "answer": "(({m} * Exp(({m} * x))) + {b})", "answerSimplification": "std", "showPreview": true, "checkingType": "absdiff", "checkingAccuracy": 0.001, "failureRate": 1, "vsetRangePoints": 5, "vsetRange": [0, 1], "checkVariableNames": false, "valuegenerators": [{"name": "x", "value": ""}]}], "sortAnswers": false}, {"type": "gapfill", "useCustomName": false, "customName": "", "marks": 0, "showCorrectAnswer": true, "showFeedbackIcon": true, "scripts": {}, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "adaptiveMarkingPenalty": 0, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "prompt": "\n\t\t\t

If $x_0=2\\;\\;\\;$what is $x_1$ correct to $4$ decimal places?

\n\t\t\t

$x_1=\\;\\;$ [[0]]

\n\t\t\t

Enter your answer to 4 decimal places.

\n\t\t\t", "gaps": [{"type": "numberentry", "useCustomName": false, "customName": "", "marks": 1, "showCorrectAnswer": true, "showFeedbackIcon": true, "scripts": {}, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "adaptiveMarkingPenalty": 0, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "minValue": "ans-tol", "maxValue": "ans+tol", "correctAnswerFraction": false, "allowFractions": false, "mustBeReduced": false, "mustBeReducedPC": 0, "showFractionHint": true, "notationStyles": ["plain", "en", "si-en"], "correctAnswerStyle": "plain"}], "sortAnswers": false}], "type": "question"}, {"name": "Simple interest", "extensions": [], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "contributors": [{"name": "Jonathan Kress", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/1952/"}], "statement": "

This question concerns simple interest

", "functions": {}, "variablesTest": {"maxRuns": 100, "condition": ""}, "parts": [{"notationStyles": ["plain", "en", "si-en"], "scripts": {}, "prompt": "

Find the interest earned when \\${principal} is invested at a flat rate of {rate}% p.a. for {n} months.

", "unitTests": [{"variables": [{"name": "principal", "value": "2060"}, {"name": "rate", "value": "6.8"}, {"name": "n", "value": "7"}, {"name": "earned", "value": "81.7133333333"}, {"name": "ratepermonth", "value": "0.5666666667"}, {"name": "notpa", "value": "140.08"}, {"name": "notpa_message", "value": "\"

You have forgotten to convert the rate to a monthly rate or use the number of months as a number of years.

\""}], "answer": {"value": "", "empty": true}, "name": "", "notes": [{"expected": {"warnings": [], "valid": false, "error": "", "messages": [], "credit": 0, "value": ""}, "name": "studentnumber"}, {"expected": {"warnings": [], "valid": false, "error": "", "messages": [], "credit": 0, "value": ""}, "name": "isfraction"}, {"expected": {"warnings": [], "valid": false, "error": "", "messages": [], "credit": 0, "value": ""}, "name": "numerator"}, {"expected": {"warnings": [], "valid": false, "error": "", "messages": [], "credit": 0, "value": ""}, "name": "isinteger"}, {"expected": {"warnings": [], "valid": false, "error": "", "messages": [], "credit": 0, "value": ""}, "name": "denominator"}, {"expected": {"warnings": [], "valid": false, "error": "", "messages": [], "credit": 0, "value": ""}, "name": "cancelled"}, {"expected": {"warnings": [], "valid": false, "error": "", "messages": [], "credit": 0, "value": ""}, "name": "cleanedstudentanswer"}, {"expected": {"warnings": [], "valid": false, "error": "", "messages": [], "credit": 0, "value": ""}, "name": "studentprecision"}, {"expected": {"warnings": [], "valid": false, "error": "", "messages": [], "credit": 0, "value": ""}, "name": "minvalue"}, {"expected": {"warnings": [], "valid": false, "error": "", "messages": [], "credit": 0, "value": ""}, "name": "maxvalue"}, {"expected": {"warnings": [], "valid": false, "error": "", "messages": [], "credit": 0, "value": ""}, "name": "validnumber"}, {"expected": {"warnings": [], "valid": false, "error": "", "messages": [], "credit": 0, "value": ""}, "name": "numberinrange"}, {"expected": {"warnings": [], "valid": false, "error": "", "messages": [], "credit": 0, "value": ""}, "name": "correctprecision"}, {"expected": {"warnings": [], "valid": false, "error": "", "messages": [], "credit": 0, "value": ""}, "name": "mark"}, {"expected": {"warnings": [], "valid": false, "error": "", "messages": [], "credit": 0, "value": ""}, "name": "interpreted_answer"}]}], "precisionType": "dp", "correctAnswerStyle": "plain", "correctAnswerFraction": false, "mustBeReduced": false, "extendBaseMarkingAlgorithm": true, "precision": "2", "customMarkingAlgorithm": "", "variableReplacementStrategy": "originalfirst", "allowFractions": false, "showPrecisionHint": true, "variableReplacements": [], "precisionMessage": "You have not given your answer to the correct precision.", "showFeedbackIcon": true, "strictPrecision": true, "mustBeReducedPC": 0, "showCorrectAnswer": true, "type": "numberentry", "marks": 1, "maxValue": "{earned}", "precisionPartialCredit": 0, "minValue": "{earned}"}], "tags": [], "variables": {"principal": {"description": "

This is the principal invested.  It is an amount in dollars.

", "group": "Ungrouped variables", "name": "principal", "definition": "random(510..2490#10)", "templateType": "randrange"}, "notpa_message": {"description": "", "group": "Ungrouped variables", "name": "notpa_message", "definition": "\"

You have forgotten to convert the rate to a monthly rate or use the number of months as a number of years.

\"", "templateType": "long string"}, "ratepermonth": {"description": "", "group": "Ungrouped variables", "name": "ratepermonth", "definition": "rate/12", "templateType": "anything"}, "notpa": {"description": "", "group": "Ungrouped variables", "name": "notpa", "definition": "principal*rate/100", "templateType": "anything"}, "rate": {"description": "

This is the interest rate per annum.

", "group": "Ungrouped variables", "name": "rate", "definition": "random(3.1..6.9#0.1)", "templateType": "randrange"}, "n": {"description": "

This is the term of the loan in months.

", "group": "Ungrouped variables", "name": "n", "definition": "random(7..35#1)", "templateType": "randrange"}, "earned": {"description": "", "group": "Ungrouped variables", "name": "earned", "definition": "principal*rate/100*n/12", "templateType": "anything"}}, "rulesets": {}, "advice": "

Don't forget that if the rate is {rate}% p.a. then the rate per month is one twelth of this, that is {ratepermonth}%.

", "metadata": {"description": "", "licence": "None specified"}, "variable_groups": [], "preamble": {"css": "", "js": ""}, "ungrouped_variables": ["principal", "rate", "n", "earned", "ratepermonth", "notpa", "notpa_message"], "type": "question"}]}], "percentPass": 0, "showstudentname": true, "name": "My first test", "type": "exam", "contributors": [{"name": "Jonathan Kress", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/1952/"}], "extensions": ["jsxgraph"], "custom_part_types": [], "resources": []}