// Numbas version: exam_results_page_options {"name": "Bill's copy of Newton-Raphson 1.2", "extensions": ["jsxgraph"], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"statement": "

Consider the following equation:

\n

\\[\\simplify[std]{g(x) = x ^ 3 + {d} * x ^ 2 + ({q * (c * q ^ 2 -(p ^ 2 * d)) -(p ^ 3)} / {p * q ^ 2}) * x + { -c} = 0}\\]

\n

\n

\n

", "name": "Bill's copy of Newton-Raphson 1.2", "rulesets": {"std": ["all", "fractionNumbers", "!collectNumbers", "!noLeadingMinus"]}, "metadata": {"description": "

Newton-Raphson numerical method question to solve $g(x)=0$

\n

Includes a graph of the function $g(x)$ in Advice using Jsxgraph.

", "licence": "Creative Commons Attribution 4.0 International"}, "functions": {"funfornr": {"language": "javascript", "definition": "var div = Numbas.extensions.jsxgraph.makeBoard('600px','200px',{boundingBox:[x1,y1,x2,y2],grid:false});\n var board = div.board;\n var d = Numbas.jme.unwrapValue(scope.variables.d);\n var c = Numbas.jme.unwrapValue(scope.variables.c);\n var p = Numbas.jme.unwrapValue(scope.variables.p);\n var q = Numbas.jme.unwrapValue(scope.variables.q);\n var ans = Numbas.jme.unwrapValue(scope.variables.ans1);\n var a1 = board.create('point',[ans,0],'$A$');\n \n \n var graph = board.create('functiongraph',function(x){return Math.pow(x,3) + d * Math.pow(x, 2) + ((q * (c * Math.pow(q,2) -(Math.pow(p, 2) * d)) -(Math.pow(p,3))) / (p * Math.pow(q,2))) * x + ( -c)});\n \n return div;\n ", "parameters": [["x1", "number"], ["y1", "number"], ["x2", "number"], ["y2", "number"]], "type": "html"}, "fun": {"language": "jme", "definition": "(2 * (x^3) + d * (x^2) + c) / (3 * (x^2) + 2 * d * x + (q * (c * q ^ 2 -(p ^ 2 * d)) -(p ^ 3)) / (p * q ^ 2))", "parameters": [["x", "number"], ["d", "number"], ["c", "number"], ["p", "number"], ["q", "number"]], "type": "number"}, "nr": {"language": "jme", "definition": "if(abs(a-fun(a,d,c,p,q))<0.001 or n=0,l+[fun(a,d,c,p,q)]+[fun(fun(a,d,c,p,q),d,c,p,q)],nr(fun(a,d,c,p,q),d,c,p,q,n-1,l+[a]))", "parameters": [["a", "number"], ["d", "number"], ["c", "number"], ["p", "number"], ["q", "number"], ["n", "number"], ["l", "list"]], "type": "number"}}, "variable_groups": [], "variables": {"tans": {"description": "", "name": "tans", "definition": "(2+d+c)/(3+2*d+c*q/p-p*d/q-p^2/q^2)", "templateType": "anything", "group": "Ungrouped variables"}, "q": {"description": "", "name": "q", "definition": "if(p=2,random(3..7),if(p=3,random(4..7),if(p=4,random(5..7),random(6..8))))", "templateType": "anything", "group": "Ungrouped variables"}, "c": {"description": "", "name": "c", "definition": "if(d=2,random(3..7),if(d=3,random(4..7),if(d=4,random(5..7),if(d=5,random(6..7),7))))", "templateType": "anything", "group": "Ungrouped variables"}, "troot": {"description": "", "name": "troot", "definition": "p/q", "templateType": "anything", "group": "Ungrouped variables"}, "ans": {"description": "", "name": "ans", "definition": "precround(tans,4)", "templateType": "anything", "group": "Ungrouped variables"}, "root": {"description": "", "name": "root", "definition": "precround(troot,2)", "templateType": "anything", "group": "Ungrouped variables"}, "ans1": {"description": "", "name": "ans1", "definition": "precround(troot,4)", "templateType": "anything", "group": "Ungrouped variables"}, "p": {"description": "", "name": "p", "definition": "random(2..5)", "templateType": "anything", "group": "Ungrouped variables"}, "d": {"description": "", "name": "d", "definition": "random(2..6)", "templateType": "anything", "group": "Ungrouped variables"}, "results": {"description": "", "name": "results", "definition": "nr(1,d,c,p,q,10,[])", "templateType": "anything", "group": "Ungrouped variables"}}, "preamble": {"js": "", "css": ""}, "advice": "

a)
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

In this question we have:
\\[\\simplify[std]{g(x) = x ^ 3 + {d} * x ^ 2 + ({q * (c * q ^ 2 -(p ^ 2 * d)) -(p ^ 3)} / {p * q ^ 2}) * x + { -c}} \\Rightarrow \\simplify[std]{g'(x) = 3 * x ^ 2 + {2 * d} * x + {q * (c * q ^ 2 -(p ^ 2 * d)) -(p ^ 3)} / {p * q ^ 2}}\\]

\n

Hence in substituting into the formula we get:

\n

\\[\\begin{eqnarray*}x_{n + 1} &=&\\simplify[std]{ x_n - ((x_n^3)+ {d} * (x_n^2)+ ({q * (c * q ^ 2 -(p ^ 2 * d)) -(p ^ 3)} / {p * q ^ 2}) * x_n + { -c}) / (3 * (x_n^2) + {2 * d} * x_n + {q * (c * q ^ 2 -(p ^ 2 * d)) -(p ^ 3)} / {p * q ^ 2})}\\\\ &=&\\simplify{(2 * (x_n^3) + {d} * (x_n^2) + {c}) / (3 * (x_n^2)+ {2 * d} * x_n + {q * (c * q ^ 2 -(p ^ 2 * d)) -(p ^ 3)} / {p * q ^ 2})} \\end{eqnarray*} \\]
You input your answers using $x$ rather than $x_n$.

\n

In the following let $ \\displaystyle f(x)=\\simplify{(2 * (x^3) + {d} * (x^2) + {c}) / (3 * (x^2) + {2 * d} * x + {q * (c * q ^ 2 -(p ^ 2 * d)) -(p ^ 3)} / {p * q ^ 2})}$

\n

b)
If $x_0=1$ then we find:

\n

\\[x_1= \\simplify[std]{(2 + {d} + {c}) / (3 + {2 * d} + {q * (c * q ^ 2 -(p ^ 2 * d)) -(p ^ 3)} / {p * q ^ 2})} = \\var{ans}\\]
to 4 decimal places.

\n

c)
We find on running the iteration that the first three values are:

\n

\\[\\begin{align}x_1&=f(x_0)=f(1)&=\\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]}\\end{align}\\]

\n

and then to 4 d.p.s

\n

\\[x=\\var{ans1}\\]

\n

Here is a graph of the function {funfornr(-5,100,5,-100)}

\n

Looking in more detail between 0 and 1 we see where it crosses the x-axis: 

\n

{funfornr(ans1-0.1,2,ans1+0.1,-2)}

", "variablesTest": {"condition": "", "maxRuns": 100}, "tags": ["graph", "iteration", "iterative method", "Jsxgraph", "jsxgraph", "JSXgraph", "Newton-Raphson method", "newton-raphson method", "numerical methods", "numerical solution", "solving a cubic equation"], "parts": [{"gaps": [{"vsetrange": [0, 1], "expectedvariablenames": [], "showCorrectAnswer": true, "answersimplification": "std", "marks": 1, "checkvariablenames": false, "vsetrangepoints": 5, "type": "jme", "notallowed": {"message": "

Do not enter decimals in your answer; enter fractions instead

", "partialCredit": 0, "showStrings": false, "strings": ["."]}, "variableReplacements": [], "checkingtype": "absdiff", "answer": "((2 * (x ^ 3)) + ({d} * (x ^ 2)) + {c})", "variableReplacementStrategy": "originalfirst", "checkingaccuracy": 0.001, "showpreview": true, "scripts": {}, "showFeedbackIcon": true}, {"vsetrange": [0, 1], "expectedvariablenames": [], "showCorrectAnswer": true, "answersimplification": "std", "marks": 1, "checkvariablenames": false, "vsetrangepoints": 5, "type": "jme", "notallowed": {"message": "

Do not enter decimals in your answer; enter fractions instead

", "partialCredit": 0, "showStrings": false, "strings": ["."]}, "variableReplacements": [], "checkingtype": "absdiff", "answer": "((3 * (x ^ 2)) + ({(2 * d)} * x) + ({((q * ((c * (q ^ 2)) + ( - ((p ^ 2) * d)))) + ( - (p ^ 3)))} / {(p * (q ^ 2))}))", "variableReplacementStrategy": "originalfirst", "checkingaccuracy": 0.001, "showpreview": true, "scripts": {}, "showFeedbackIcon": true}], "scripts": {}, "prompt": "\n

This equation has a root in the range $0 \\lt x \\lt 1$.
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

$p(x_n)=\\;\\;$[[0]]
In your answer simply use $x$ instead of $x_n$.
Do not enter decimals in this part of the question; enter fractions instead

\n

$g'(x_n)=\\;\\;$[[1]]
In your answer simply use $x$ instead of $x_n$.
Do not enter decimals in this part of the question; enter fractions instead

\n

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 ", "stepsPenalty": 0, "marks": 0, "type": "gapfill", "variableReplacements": [], "showFeedbackIcon": true, "showCorrectAnswer": true, "variableReplacementStrategy": "originalfirst", "steps": [{"expectedvariablenames": [], "showCorrectAnswer": true, "type": "jme", "checkvariablenames": false, "vsetrangepoints": 5, "marks": 0, "vsetrange": [0, 1], "variableReplacements": [], "checkingtype": "absdiff", "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": "", "variableReplacementStrategy": "originalfirst", "checkingaccuracy": 0.001, "showpreview": true, "scripts": {}, "showFeedbackIcon": true}]}, {"variableReplacementStrategy": "originalfirst", "scripts": {}, "prompt": "\n \n \n

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

\n \n \n \n

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

\n \n \n \n

Enter your answer to 4 decimal places.

\n \n \n \n ", "marks": 0, "type": "gapfill", "variableReplacements": [], "showFeedbackIcon": true, "showCorrectAnswer": true, "gaps": [{"type": "numberentry", "correctAnswerStyle": "plain", "marks": 1, "allowFractions": false, "showFeedbackIcon": true, "showCorrectAnswer": true, "minValue": "ans-0.0001", "variableReplacements": [], "notationStyles": ["plain", "en", "si-en"], "variableReplacementStrategy": "originalfirst", "maxValue": "ans+0.0001", "correctAnswerFraction": false, "scripts": {}}]}, {"variableReplacementStrategy": "originalfirst", "scripts": {}, "prompt": "\n \n \n

Continue the iterative process to find the root $x$ of $g(x)=0$ of (correct to 2 d.p.).

\n \n \n \n

$x=\\;\\;$[[0]]
(Enter your answer to 2 d.p.)

\n \n \n \n ", "marks": 0, "type": "gapfill", "variableReplacements": [], "showFeedbackIcon": true, "showCorrectAnswer": true, "gaps": [{"type": "numberentry", "correctAnswerStyle": "plain", "marks": 1, "allowFractions": false, "showFeedbackIcon": true, "showCorrectAnswer": true, "minValue": "root-0.01", "variableReplacements": [], "notationStyles": ["plain", "en", "si-en"], "variableReplacementStrategy": "originalfirst", "maxValue": "root+0.01", "correctAnswerFraction": false, "scripts": {}}]}], "ungrouped_variables": ["c", "d", "p", "ans1", "results", "q", "troot", "ans", "root", "tans"], "extensions": ["jsxgraph"], "type": "question", "contributors": [{"name": "Bill Foster", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/6/"}]}]}], "contributors": [{"name": "Bill Foster", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/6/"}]}