Using Matlab: Function Name: reversePascal Inputs: 1. (double) A vector of polyn
ID: 664434 • Letter: U
Question
Using Matlab:
Function Name: reversePascal
Inputs:
1. (double) A vector of polynomial coefficients
Outputs:
(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 (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.
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:
[14641] <-- subtract 0 from 1 [13641] <-- subtract 1 from 4 [13341] <-- subtract 3 from 6 [13311] <-- subtract 3 from 4 [13310] <-- 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.
You MUST use recursion to solve the problem.
Explanation / Answer
function y = reversePascal(pol_coeff,n)
if n==3
fprintf('out1 => [%d %d]',pol_coeff(1),pol_coeff(3));
fprintf('out2 => %d',pol_coeff(2));
else
for i=1:n
if i==1
pol_coeff(i)=pol_coeff(i)-0;
else
pol_coeff(i)=pol_coeff(i)-pol_coeff(i-1);
end
end
reversePascal(pol_coeff,n-1);
end
end
prompt='Enter no. of polynomial coefficients';
n=input(prompt)
pol_coeff = ones(1,n);
for x=1:n
prompt='Enter the polynomial coefficient'
pol_coeff(x) = input(prompt);
end
reversePascal(pol_coeff,n);
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.