// Numbas version: finer_feedback_settings {"showQuestionGroupNames": false, "duration": 0, "question_groups": [{"pickQuestions": 1, "name": "Group", "pickingStrategy": "all-ordered", "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\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", "licence": "Creative Commons Attribution 4.0 International"}, "statement": "\n\tConsider 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", "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('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", "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$
If $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", "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": "Polynomial questions", "extensions": [], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "contributors": [{"name": "joelle pearn", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/2968/"}], "variablesTest": {"maxRuns": 100, "condition": ""}, "rulesets": {}, "metadata": {"description": "", "licence": "None specified"}, "functions": {}, "ungrouped_variables": [], "variable_groups": [{"name": "part a", "variables": ["a", "b", "x0"]}, {"name": "part b", "variables": ["a2", "b2", "c2"]}, {"name": "part c", "variables": ["b3", "c3", "r2", "r1", "a3"]}, {"name": "part d", "variables": ["m", "p", "wc", "d"]}], "advice": "", "parts": [{"variableReplacements": [], "correctAnswerStyle": "plain", "showFeedbackIcon": true, "correctAnswerFraction": false, "mustBeReduced": false, "extendBaseMarkingAlgorithm": true, "scripts": {}, "showCorrectAnswer": true, "allowFractions": false, "prompt": "Consider functions like $\\simplify{f(x)=ax+b}$
\nSuppose $\\simplify{f(x) = {a}*x+{b}}$
\nfind $f(\\var{x0})$
", "minValue": "a*x0+b", "type": "numberentry", "notationStyles": ["plain", "en", "si-en"], "marks": 1, "customMarkingAlgorithm": "", "mustBeReducedPC": 0, "maxValue": "a*x0+b", "unitTests": [], "variableReplacementStrategy": "originalfirst"}, {"checkingType": "absdiff", "variableReplacements": [], "showFeedbackIcon": true, "extendBaseMarkingAlgorithm": true, "scripts": {}, "showCorrectAnswer": true, "failureRate": 1, "checkVariableNames": false, "prompt": "differentiate the quadratic $\\simplify[all,!noleadingminus] {g(x)={a2}*x^2+{b2}*x+{c2}}$
", "vsetRangePoints": 5, "checkingAccuracy": 0.001, "vsetRange": [0, 1], "expectedVariableNames": [], "type": "jme", "marks": 1, "showPreview": true, "customMarkingAlgorithm": "", "answer": "{2*a2}*x + {b2}", "unitTests": [], "variableReplacementStrategy": "originalfirst"}, {"checkingType": "absdiff", "showCorrectAnswer": true, "stepsPenalty": 0, "prompt": "List the roots of the quadratic
\n$\\simplify{h(x)={a3}x^2+{b3}x+{c3}}$
\nuse the Numbas syntas set(y,z)
If the roots of a quadratic $r$ and $s$, then the quadratic is $(x-r)(x-s)=x^2-(r+s)x+rs
\nIn this case, which of these statements are true?
", "showCellAnswerState": true, "type": "1_n_2", "displayColumns": 0, "marks": 0, "distractors": ["", "", ""], "customMarkingAlgorithm": "", "shuffleChoices": false, "maxMarks": 0, "choices": ["$\\simplify{r+s=-{b3}}$ and $\\simplify{r*s={c3}}$", "$\\simplify{r+s={b3}}$ and $\\simplify{r*s={c3}}$", "$\\simplify{r+s=-{b3}}$ and $\\simplify{r*s=-{c3}}$"], "unitTests": [], "variableReplacementStrategy": "originalfirst"}], "failureRate": 1, "unitTests": [], "checkingAccuracy": 0.001, "checkVariableNames": false, "marks": 1, "variableReplacementStrategy": "originalfirst", "vsetRangePoints": 5, "vsetRange": [0, 1]}, {"precisionMessage": "You have not given your answer to the correct precision.", "precisionType": "dp", "maxValue": "1.2*{p}*{m}/60*{wc}", "showCorrectAnswer": true, "unitTests": [], "prompt": "Every day, a 1200-watt microwave oven is used for {m} minutes at {p}% power. Electricity is charged at \\${wc} per kWh. What is the cost of running this microwave oven for {d} days?
", "extendBaseMarkingAlgorithm": true, "type": "numberentry", "customMarkingAlgorithm": "", "showPrecisionHint": true, "mustBeReducedPC": 0, "scripts": {}, "precisionPartialCredit": "30", "variableReplacements": [], "precision": "2", "correctAnswerStyle": "plain", "showFeedbackIcon": true, "mustBeReduced": false, "allowFractions": false, "strictPrecision": true, "minValue": "1.2*{p/100}*{m}/60*{wc}", "notationStyles": ["plain", "en", "si-en"], "correctAnswerFraction": false, "marks": 1, "variableReplacementStrategy": "originalfirst"}], "preamble": {"js": "", "css": ""}, "variables": {"b2": {"name": "b2", "description": "", "templateType": "anything", "group": "part b", "definition": "random(-10..10)"}, "a2": {"name": "a2", "description": "", "templateType": "anything", "group": "part b", "definition": "random(-10..10 except 0)"}, "r2": {"name": "r2", "description": "", "templateType": "anything", "group": "part c", "definition": "random(-10..10 except r1)"}, "c2": {"name": "c2", "description": "", "templateType": "randrange", "group": "part b", "definition": "random(-5..8#1)"}, "c3": {"name": "c3", "description": "", "templateType": "anything", "group": "part c", "definition": "r1*r2"}, "wc": {"name": "wc", "description": "cost per kilowatt
", "templateType": "anything", "group": "part d", "definition": "random(0.2..1 #0.2)"}, "x0": {"name": "x0", "description": "his defines which value for f(x)
", "templateType": "randrange", "group": "part a", "definition": "random(-5..5#1)"}, "d": {"name": "d", "description": "number of days
", "templateType": "anything", "group": "part d", "definition": "random(30..300)"}, "a3": {"name": "a3", "description": "", "templateType": "anything", "group": "part c", "definition": "random(-10..10)"}, "p": {"name": "p", "description": "this stands for percentage of power used
", "templateType": "anything", "group": "part d", "definition": "random(25..80)"}, "m": {"name": "m", "description": "this stands for minutes
", "templateType": "anything", "group": "part d", "definition": "random(5..55)"}, "r1": {"name": "r1", "description": "", "templateType": "anything", "group": "part c", "definition": "random(-10..10 except 0)"}, "b": {"name": "b", "description": "this is the constant term
", "templateType": "randrange", "group": "part a", "definition": "random(-5..5#1)"}, "a": {"name": "a", "description": "This is the coefficient of x. note random values: means all numbers between -10 and 10 except 0. if wanted to go incement steps, type in#the increment value
", "templateType": "anything", "group": "part a", "definition": "random(-10..10 except 0)"}, "b3": {"name": "b3", "description": "", "templateType": "anything", "group": "part c", "definition": "-(r1+r2)"}}, "statement": "this question is about manipulating polynomials.- note declaring variables, a2,b2,c2
", "tags": [], "type": "question"}]}], "name": "first exam try", "percentPass": 0, "navigation": {"onleave": {"action": "none", "message": ""}, "preventleave": true, "allowregen": true, "showfrontpage": true, "browse": true, "showresultspage": "oncompletion", "reverse": true}, "showstudentname": true, "timing": {"allowPause": true, "timedwarning": {"action": "none", "message": ""}, "timeout": {"action": "none", "message": ""}}, "metadata": {"licence": "None specified", "description": ""}, "feedback": {"showtotalmark": true, "intro": "", "feedbackmessages": [], "advicethreshold": 0, "showactualmark": true, "showanswerstate": true, "allowrevealanswer": true, "enterreviewmodeimmediately": true, "showexpectedanswerswhen": "inreview", "showpartfeedbackmessageswhen": "always", "showactualmarkwhen": "always", "showtotalmarkwhen": "always", "showanswerstatewhen": "always", "showadvicewhen": "never"}, "type": "exam", "contributors": [{"name": "joelle pearn", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/2968/"}], "extensions": ["jsxgraph"], "custom_part_types": [], "resources": []}