Recursion
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi, I am having some trouble figuring out this recursion problem. Can anyone help?
Function Name: reversePascal Inputs (1): - (double) A vector of polynomial coefficients. Outputs (1): - (double) A vector of binomial coefficients. - (double) The exponent of the binomial.
Function Description:
Write a function called "reversePascal" that takes the coefficients to
an arbitrarily long polynomial and condenses it into the form (ax+b)^n,
or binomial form. The function should return [a b] as its first output,
and n as its second. You MUST use recursion to solve this problem.
Notes:
- The input polynomial will always be reducible into a binomial.
Test Cases:
[vec1 n1] = reversePascal([1 8 18 16 5]); vec1 => [1 5] n1 => 4
[vec2 n2] = reversePascal([5 16 18 8 1]); vec2 => [5 1] n2 => 4
[vec3 n3] = reversePascal([-1 -2 2 8 7 2]); vec3 => [-1 2] n3 => 5
[vec4 n4] = reversePascal([-2 -2]);
vec3 => [-2 -2]
n3 => 1
0 Kommentare
Antworten (1)
Geoff
am 23 Mär. 2012
Well, the thing with recursion is you take a larger problem and make it slightly smaller. So, to begin with you test whether you need to break the problem down and if so, you make a single recursive call that simplifies the problem by one step.
Since this is a homework problem, we can't give you the answer, but we can try to point you in the right direction.
So consider this...
1. If the problem is reduced to its simplest form, just return the required answer.
2. If the problem is larger, recursively call your function with a slightly smaller problem (perhaps one less term?)
Remember that the result of (2) will always be the solution to the slightly smaller problem, so you have to adjust the result to account for that.
I hope that helps.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!