// Numbas version: finer_feedback_settings {"name": "Maths_and_Stats's copy of Interactive Newton-Raphson method", "extensions": ["jsxgraph"], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"statement": "\n\t
Consider the following equation.
\n\t\\[\\simplify[std]{e^({m}x)+{b}x-{a}=0}\\]
\n\tFind the approximate solution in the range $0 \\le x \\le 1$ by using the Newton-Raphson method.
\n\tThe 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\ta)
\n\tRecall 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$
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}))}\\]
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})}\\]
(In your answers you would input $x$ rather than $x_n$.)
\n\tIn the following let $\\displaystyle f(x)=\\simplify[std]{ (({m} * x -1) * Exp({m} * x ) + {a}) / ({m} * Exp({m} * x ) + {b})}$
\n\tb)
\n\tIf $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})}\\]
which to 4 decimal places is: $\\;\\;x_1= \\var{ans}$
\n\tWe 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\tSo the solution to the equation to four decimal places for $0 \\le x \\le 1$ is $x=\\var{precround(ans1,4)}$
\n\tHere 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\tNote that you can slide the first approximation $x_0$ along the x-axis to see the effect of changing the starting value.
\n\t", "functions": {"nr": {"parameters": [["m", "number"], ["b", "number"], ["a", "number"], ["c", "number"], ["n", "number"], ["l", "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]))", "type": "list"}, "funfornr": {"parameters": [], "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", "type": "html"}, "fun": {"parameters": [["m", "number"], ["b", "number"], ["a", "number"], ["c", "number"]], "language": "jme", "definition": "((m*c-1)*e^(m*c)+a)/(m*e^(m*c)+b)", "type": "number"}, "test": {"parameters": [["m", "number"], ["b", "number"], ["a", "number"], ["maxy", "number"]], "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('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$
This equation has a root in the range $0 \\lt x \\lt 1$.
\n\t\t\tUsing 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.
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\tIf 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", "customMarkingAlgorithm": "", "variableReplacements": [], "type": "gapfill"}, {"variableReplacementStrategy": "originalfirst", "scripts": {}, "unitTests": [], "gaps": [{"unitTests": [], "maxValue": "ans+tol", "correctAnswerFraction": false, "minValue": "ans-tol", "adaptiveMarkingPenalty": 0, "mustBeReducedPC": 0, "customName": "", "showFractionHint": true, "notationStyles": ["plain", "en", "si-en"], "useCustomName": false, "variableReplacementStrategy": "originalfirst", "scripts": {}, "showCorrectAnswer": true, "customMarkingAlgorithm": "", "marks": 1, "mustBeReduced": false, "extendBaseMarkingAlgorithm": true, "correctAnswerStyle": "plain", "showFeedbackIcon": true, "allowFractions": false, "variableReplacements": [], "type": "numberentry"}], "marks": 0, "adaptiveMarkingPenalty": 0, "showCorrectAnswer": true, "customName": "", "useCustomName": false, "extendBaseMarkingAlgorithm": true, "showFeedbackIcon": true, "sortAnswers": false, "prompt": "\n\t\t\tIf $x_0=2\\;\\;\\;$what is $x_1$ correct to $4$ decimal places?
\n\t\t\t$x_1=\\;\\;$ [[0]]
\n\t\t\tEnter your answer to 4 decimal places.
\n\t\t\t", "customMarkingAlgorithm": "", "variableReplacements": [], "type": "gapfill"}], "metadata": {"licence": "Creative Commons Attribution 4.0 International", "description": "\n\t\tWrite 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\tIncluded in the Advice of this question are:
\n\t\t6 iterations of the method.
\n\t\tGraph of the NR process using jsxgraph. Also user interaction allowing change of starting value and its effect on the process.
\n\t\t"}, "variables": {"m": {"templateType": "anything", "group": "Ungrouped variables", "description": "", "name": "m", "definition": "random(1.5..2#0.1)"}, "a": {"templateType": "anything", "group": "Ungrouped variables", "description": "", "name": "a", "definition": "random(8..15)"}, "tans": {"templateType": "anything", "group": "Ungrouped variables", "description": "", "name": "tans", "definition": "((2*m-1)*exp(2*m)+a)/(m*exp(2*m)+b)"}, "tol": {"templateType": "anything", "group": "Ungrouped variables", "description": "", "name": "tol", "definition": "0"}, "ans": {"templateType": "anything", "group": "Ungrouped variables", "description": "", "name": "ans", "definition": "precround(tans,4)"}, "results": {"templateType": "anything", "group": "Ungrouped variables", "description": "", "name": "results", "definition": "nr(m,b,a,2,10,[])"}, "maxy": {"templateType": "anything", "group": "Ungrouped variables", "description": "", "name": "maxy", "definition": "ceil(e^(2*m)+2*b-a)+5"}, "b": {"templateType": "anything", "group": "Ungrouped variables", "description": "", "name": "b", "definition": "random((a+1)..9)"}, "ans1": {"templateType": "anything", "group": "Ungrouped variables", "description": "", "name": "ans1", "definition": "precround(results[6],4)"}}, "name": "Maths_and_Stats's copy of Interactive Newton-Raphson method", "rulesets": {"std": ["all", "!collectNumbers", "!noLeadingMinus"]}, "preamble": {"css": "", "js": ""}, "variablesTest": {"condition": "", "maxRuns": 100}, "ungrouped_variables": ["a", "m", "ans1", "ans", "b", "tol", "tans", "maxy", "results"], "tags": [], "extensions": ["jsxgraph"], "type": "question", "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/"}, {"name": "Maths_and_Stats Advice", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/3596/"}]}]}], "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/"}, {"name": "Maths_and_Stats Advice", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/3596/"}]}