Cody

# Problem 42775. Raise a polynomial to a power

Solution 2093493

Submitted on 15 Jan 2020
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
p=[2]; N=8; y_correct=256; assert(isequal(polypow(p,N),y_correct))

2   Fail
p=[1 1]; N=1; y_correct=[1 1]; assert(isequal(polypow(p,N),y_correct))

Error using ^ (line 51) Incorrect dimensions for raising a matrix to a power. Check that the matrix is square and the power is a scalar. To perform elementwise matrix powers, use '.^'. Error in polypow (line 2) q = p^N; Error in Test2 (line 4) assert(isequal(polypow(p,N),y_correct))

3   Fail
p=[1 1]; N=5; y_correct=[1 5 10 10 5 1]; assert(isequal(polypow(p,N),y_correct))

Error using ^ (line 51) Incorrect dimensions for raising a matrix to a power. Check that the matrix is square and the power is a scalar. To perform elementwise matrix powers, use '.^'. Error in polypow (line 2) q = p^N; Error in Test3 (line 4) assert(isequal(polypow(p,N),y_correct))

4   Fail
p=1:5; N=3; y_correct=[1 6 21 56 126 234 369 504 594 574 465 300 125]; assert(isequal(polypow(p,N),y_correct))

Error using ^ (line 51) Incorrect dimensions for raising a matrix to a power. Check that the matrix is square and the power is a scalar. To perform elementwise matrix powers, use '.^'. Error in polypow (line 2) q = p^N; Error in Test4 (line 4) assert(isequal(polypow(p,N),y_correct))

5   Fail
p=5:-1:1; N=3; y_correct=[125 300 465 574 594 504 369 234 126 56 21 6 1]; assert(isequal(polypow(p,N),y_correct))

Error using ^ (line 51) Incorrect dimensions for raising a matrix to a power. Check that the matrix is square and the power is a scalar. To perform elementwise matrix powers, use '.^'. Error in polypow (line 2) q = p^N; Error in Test5 (line 4) assert(isequal(polypow(p,N),y_correct))

6   Fail
p=5:-1:1; N=1; y_correct=[5 4 3 2 1]; assert(isequal(polypow(p,N),y_correct))

Error using ^ (line 51) Incorrect dimensions for raising a matrix to a power. Check that the matrix is square and the power is a scalar. To perform elementwise matrix powers, use '.^'. Error in polypow (line 2) q = p^N; Error in Test6 (line 4) assert(isequal(polypow(p,N),y_correct))