RECURSION Function Name: reversePascal Inputs: 1. (double) A vector of polynomia
ID: 665061 • Letter: R
Question
RECURSION
Function Name: reversePascal
Inputs:
1. (double) A vector of polynomial coefficients
Outputs:
1. (double) A vector of binomial coefficients
2. (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 (x+1)^n, or binomial form. The function should return [1 1] as its first output, and n as its second output.
Example: The polynomial x^2 +2x +1 has coefficients [1 2 1]. It can also be written as (x+1)^2.
[out1, out2] = reversePascal([1 2 1])
out1 => [1 1]
out2 => 2
While there are many ways to do this problem, the recommended method outlined below involves reversing up Pascal’s Triangle. For more information about Pascal’s Triangle, go to
http://en.wikipedia.org/wiki/Pascal%27s_triangle
Recommended Method:
Each instance of the function should check if the input is already a binomial in the form [1 1]. If it is, it should return that from the function. If it is not, the function step through the polynomial left to right and subtract the previous index from the current index.
Example:
[1 4 6 4 1] <-- subtract 0 from 1
[1 3 6 4 1] <-- subtract 1 from 4
[1 3 3 4 1] <-- subtract 3 from 6
[1 3 3 1 1] <-- subtract 3 from 4
[1 3 3 1 0] <-- subtract 1 from 1
At this point, the function should remove the zero from the end of the vector and then call itself on this new vector.
Notes:
The input polynomial will always be reducible into a binomial
Explanation / Answer
#include long factorial(int); int main() { int i, n, c; printf("Enter the number of rows you wish to see in pascal triangle "); scanf("%d",&n); for (i = 0; iRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.