// Numbas version: finer_feedback_settings {"name": "Order 2 Recurrence", "extensions": [], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"name": "Order 2 Recurrence", "tags": [], "metadata": {"description": "

In this question the students have to solve a linear recurrence of order 2. The sequence is asked in recurrence form and the goal is to find its closed form.

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

Solve the recurrence relation given by: \\begin{cases} a_0 &= \\var{a0}\\\\ a_1 &= \\var{a1}\\\\ a_n &=\\simplify{{recurrence}} \\end{cases}

", "advice": "

To find the closed form of a linear recurrence of order 2, we have to follow three steps:

\n
    \n
  1. Find the characteristic equation.
  2. \n
  3. Solve the characteristic equation to obtain the general form of the sequence.
  4. \n
  5. Find the specific parameters by solving a system of simultaneous equations.
  6. \n
\n

Finding the characteristic equation.

\n

To find the characteristic equation, we first need to rewrite ther recurrence relation to have 0 on the right hand side.

\n

\\[\\begin{align*} a_{n+2} &= \\simplify{{recurrence}} \\\\ \\var{relation} &= 0 \\end{align*}\\]

\n

Since this relation must be true for every \\(n\\geq 2\\), it must also apply for \\(n=2\\): \\[\\var{r2}=0\\]

\n

Now, we substitute each \\(a_{i}\\) with \\(x^i\\), to get the characteristic equation: \\[\\var{charac}=0\\].

\n

Solving the characteristic equation.

\n

We can solve the characteristic equation using the quadratic formula: \\[\\frac{-b\\pm \\sqrt{b^2-4ac}}{2}.\\] Here we have \\(a=1\\), \\(b=\\simplify{-{c1}}\\) and \\(c=\\simplify{-{c2}}\\). So the quadratic formula gives us two solutions to that equation: \\(x_1 = \\var{roots[0]}\\) and \\(x_2 = \\var{roots[1]}\\). Make sure to verify your intermediate result at this stage by plugging these values back into your equation.

\n

The general form of the sequence is therefore: \\[a_n = \\simplify{s_1*({x1})^n + s_2*({x2})^n}.\\]

\n

Finding the parameters \\(s_1\\) and \\(s_2\\).

\n

To find the parameters \\(s_1\\) and \\(s_2\\) we use the values of the elements \\(a_0\\) and \\(a_1\\).

\n\n

And so we obtain the simultaneous equations: \\[ \\begin{cases} s_1 + s_2 &= \\var{a0}\\\\ \\simplify{+{x1}*s_1 +{x2}*s_2} &= \\var{a1} \\end{cases}. \\]

\n

We can solve this system of linear equations, for example by elimination. Let's eliminate $s_2$:

\n
    \n
  1. Multiply the top equation by $\\var{x2}$ (the coefficient of $s_2$ in the bottom equation): $\\simplify{{x2}*s_1 + {x2}*s_2}=\\var{x2*a0}$.
  2. \n
  3. Subtract the second equation from the first: \\[\\simplify{({x2}-{x1})*s_1} = \\var{x2*a0-a1}.\\]
  4. \n
  5. Solve for $s_1$ using the equation we just obtained: $s_1=\\var{s1}$.
  6. \n
  7. Substitute the value of $s_1$ into the top equation: $s_2=\\var{a0}-s_1 = \\var{s2}$.
  8. \n
\n

We find that \\(s_1 = \\var{s1}\\) and \\(s_2=\\var{s2}\\). Make sure to verify your intermediate result at this stage by plugging these values back into the two simultaneous equations.

\n

Therefore the closed form is \\[a_n = \\var{closedForm}.\\] Evaluate at least \\(a_0\\), \\(a_1\\) and \\(a_2\\) with your closed form solution before entering it into the quiz.

", "rulesets": {}, "extensions": [], "builtin_constants": {"e": true, "pi,\u03c0": true, "i": true}, "constants": [], "variables": {"rootSet": {"name": "rootSet", "group": "Parameters", "definition": "-10..10 except 0", "description": "", "templateType": "anything", "can_override": false}, "order": {"name": "order", "group": "Parameters", "definition": "2", "description": "", "templateType": "anything", "can_override": false}, "roots": {"name": "roots", "group": "Randomised parameters", "definition": "shuffle(rootSet)[0..order]", "description": "", "templateType": "anything", "can_override": false}, "charac": {"name": "charac", "group": "Generated Values", "definition": "simplify(expression(\"(x-{roots[0]})*(x-{roots[1]})\"),[\"all\",\"expandbrackets\"])", "description": "", "templateType": "anything", "can_override": false}, "c1": {"name": "c1", "group": "Generated Values", "definition": "roots[0]+roots[1]", "description": "", "templateType": "anything", "can_override": false}, "c2": {"name": "c2", "group": "Generated Values", "definition": "-roots[0]*roots[1]", "description": "", "templateType": "anything", "can_override": false}, "closedForm": {"name": "closedForm", "group": "Generated Values", "definition": "simplify(expression(\"{s1}*({roots[0]})^n+{s2}*({roots[1]})^n\"),[\"all\"])", "description": "", "templateType": "anything", "can_override": false}, "s2": {"name": "s2", "group": "Randomised parameters", "definition": "random(-5..5)", "description": "", "templateType": "anything", "can_override": false}, "s1": {"name": "s1", "group": "Randomised parameters", "definition": "random(-3..3)", "description": "", "templateType": "anything", "can_override": false}, "a0": {"name": "a0", "group": "Generated Values", "definition": "s1+s2", "description": "", "templateType": "anything", "can_override": false}, "a1": {"name": "a1", "group": "Generated Values", "definition": "s1*roots[0]+s2*roots[1]", "description": "", "templateType": "anything", "can_override": false}, "recurrence": {"name": "recurrence", "group": "Generated Values", "definition": "simplify(expression(\"{c1}*sub(a,n-1)+{c2}*sub(a,n-2)\"),[\"all\"])", "description": "", "templateType": "anything", "can_override": false}, "a2": {"name": "a2", "group": "Feedback", "definition": "c1*a1+c2*a0", "description": "", "templateType": "anything", "can_override": false}, "a3": {"name": "a3", "group": "Feedback", "definition": "c1*a2+c2*a1", "description": "", "templateType": "anything", "can_override": false}, "relation": {"name": "relation", "group": "Advice", "definition": "simplify(expression(\"sub(a,n) - ({recurrence})\"),[\"basic\"])", "description": "", "templateType": "anything", "can_override": false}, "r2": {"name": "r2", "group": "Advice", "definition": "simplify(expression(\"sub(a,2)-{c1}*sub(a,1)-{c2}*sub(a,0)\"),[\"basic\"])", "description": "", "templateType": "anything", "can_override": false}, "test": {"name": "test", "group": "Ungrouped variables", "definition": "roots[1]", "description": "", "templateType": "anything", "can_override": false}, "x1": {"name": "x1", "group": "Advice", "definition": "roots[0]", "description": "", "templateType": "anything", "can_override": false}, "x2": {"name": "x2", "group": "Advice", "definition": "roots[1]", "description": "", "templateType": "anything", "can_override": false}}, "variablesTest": {"condition": "not (roots[0] = -roots[1])", "maxRuns": 100}, "ungrouped_variables": ["test"], "variable_groups": [{"name": "Parameters", "variables": ["rootSet", "order"]}, {"name": "Randomised parameters", "variables": ["roots", "s1", "s2"]}, {"name": "Generated Values", "variables": ["charac", "c1", "c2", "closedForm", "a0", "a1", "recurrence"]}, {"name": "Feedback", "variables": ["a2", "a3"]}, {"name": "Advice", "variables": ["relation", "r2", "x1", "x2"]}], "functions": {"subvalue": {"parameters": [["ex", "expression"], ["k", "number"]], "type": "expression", "language": "jme", "definition": "substitute([\"n\":k],ex)"}}, "preamble": {"js": "", "css": ""}, "parts": [{"type": "jme", "useCustomName": false, "customName": "", "marks": 1, "scripts": {}, "customMarkingAlgorithm": "azero (check that the student's answer is correct for n=0):\n assert(resultsequal(unset(question_definitions,eval(studentCompare,['n':0])),unset(question_definitions,eval(correctCompare,['n':0])),settings[\"checkingType\"],settings[\"checkingAccuracy\"]),\n negative_feedback(render(safe(\"

Your formula fails for $n=0$. We expect that $a_0=\\\\var{a0}$, but with your formula we get $a_0=\\\\var{nex}=\\\\var{nv}$.

It is likely that you made a mistake while solving the linear system, at the and. You could have caught this mistake by plugging the values back into the equations before entering them into Numbas.

\"),[\"nex\":subvalue(studentCompare,0),\"nv\":eval(studentCompare,['n':0])])))\n\n\naone (check that the student's answer is correct for n=0):\n assert(resultsequal(unset(question_definitions,eval(studentCompare,['n':1])),unset(question_definitions,eval(correctCompare,['n':1])),settings[\"checkingType\"],settings[\"checkingAccuracy\"]),\n negative_feedback(render(safe(\"

Your formula fails for n=1. We expect that $a_1=\\\\var{a1}$, but with your formula we get $a_1=\\\\var{nex}=\\\\var{nv}$.

It is likely that you made a mistake while solving the linear system, at the and. You could have caught this mistake by plugging the values back into the equations before entering them into Numbas.

\"),[\"nex\":subvalue(studentCompare,1),\"nv\":eval(studentCompare,['n':1])])))\n\natwo (check that the student's answer is correct for n=2):\n assert(resultsequal(unset(question_definitions,eval(studentCompare,['n':2])),unset(question_definitions,eval(correctCompare,['n':2])),settings[\"checkingType\"],settings[\"checkingAccuracy\"]),\n negative_feedback(render(safe(\"

Your formula fails for n=2. We expect that $a_2=\\\\var{a2}$, but with your formula we get $a_2=\\\\var{nex}=\\\\var{nv}$.

It seems that you made a mistake when solving the quadratic equation, or when finding the characteristic polynomial. You probably could have caught the mistake by plugging the values into the equation.

\"),[\"nex\":subvalue(studentCompare,2),\"nv\":eval(studentCompare,['n':2])])))\n\nmark:\n apply(studentExpr);\n apply(failNameToCompare);\n apply(unexpectedVariables);\n apply(sameVars);\n apply(azero);\n apply(aone);\n apply(atwo);\n apply(numericallyCorrect);\n apply(failMinLength);\n apply(failMaxLength);\n apply(forbiddenStringsPenalty);\n apply(requiredStringsPenalty);\n apply(failMatchPattern)", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "prompt": "

Note the index! $a_n =$

", "answer": "{closedForm}", "showPreview": true, "checkingType": "absdiff", "checkingAccuracy": 0.001, "failureRate": 1, "vsetRangePoints": 5, "vsetRange": [0, 1], "checkVariableNames": false, "singleLetterVariables": false, "allowUnknownFunctions": true, "implicitFunctionComposition": false, "caseSensitive": false, "valuegenerators": []}], "partsMode": "all", "maxMarks": 0, "objectives": [], "penalties": [], "objectiveVisibility": "always", "penaltyVisibility": "always", "type": "question", "contributors": [{"name": "Julien Ugon", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/3575/"}]}]}], "contributors": [{"name": "Julien Ugon", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/3575/"}]}