Cody

# Problem 1475. Chebyshev polynomials of the 2nd Kind

Solution 1938621

Submitted on 16 Sep 2019 by Augusto Mazzei
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
user_solution = fileread('chebyshev2ndKindPoly.m'); assert(isempty(strfind(user_solution,'regexp'))); assert(isempty(strfind(user_solution,'2str'))); assert(isempty(strfind(user_solution,'str2'))); assert(isempty(strfind(user_solution,'interp'))); assert(isempty(strfind(user_solution,'printf'))); assert(isempty(strfind(user_solution,'assert')));

2   Pass
n = 0; P_correct = [1]; assert(isequal(chebyshev2ndKindPoly(n),P_correct));

ans = 1

3   Pass
n = 1; P_correct = [2 0]; assert(isequal(chebyshev2ndKindPoly(n),P_correct));

A = 1×3 cell array {[1]} {1×2 double} {1×3 double} ans = 2 0

4   Pass
n = 2; P_correct = [4 0 -1]; assert(isequal(chebyshev2ndKindPoly(n),P_correct));

A = 1×3 cell array {[1]} {1×2 double} {1×3 double} A = 1×4 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} ans = 4 0 -1

5   Pass
n = 3; P_correct = [8 0 -4 0]; assert(isequal(chebyshev2ndKindPoly(n),P_correct));

A = 1×3 cell array {[1]} {1×2 double} {1×3 double} A = 1×4 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} A = 1×5 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} ans = 8 0 -4 0

6   Pass
n = 4; P_correct = [16 0 -12 0 1]; assert(isequal(chebyshev2ndKindPoly(n),P_correct));

A = 1×3 cell array {[1]} {1×2 double} {1×3 double} A = 1×4 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} A = 1×5 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} A = 1×6 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} ans = 16 0 -12 0 1

7   Pass
n = 5; P_correct = [32 0 -32 0 6 0]; assert(isequal(chebyshev2ndKindPoly(n),P_correct));

A = 1×3 cell array {[1]} {1×2 double} {1×3 double} A = 1×4 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} A = 1×5 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} A = 1×6 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} A = 1×7 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} ans = 32 0 -32 0 6 0

8   Pass
n = 6; P_correct = [64 0 -80 0 24 0 -1]; assert(isequal(chebyshev2ndKindPoly(n),P_correct));

A = 1×3 cell array {[1]} {1×2 double} {1×3 double} A = 1×4 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} A = 1×5 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} A = 1×6 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} A = 1×7 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} A = 1×8 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} ans = 64 0 -80 0 24 0 -1

9   Pass
n = 7; P_correct = [128 0 -192 0 80 0 -8 0]; assert(isequal(chebyshev2ndKindPoly(n),P_correct));

A = 1×3 cell array {[1]} {1×2 double} {1×3 double} A = 1×4 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} A = 1×5 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} A = 1×6 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} A = 1×7 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} A = 1×8 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} A = 1×9 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} {1×9 double} ans = 128 0 -192 0 80 0 -8 0

10   Pass
n = 8; P_correct = [256 0 -448 0 240 0 -40 0 1]; assert(isequal(chebyshev2ndKindPoly(n),P_correct));

A = 1×3 cell array {[1]} {1×2 double} {1×3 double} A = 1×4 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} A = 1×5 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} A = 1×6 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} A = 1×7 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} A = 1×8 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} A = 1×9 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} {1×9 double} A = 1×10 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} {1×9 double} {1×10 double} ans = 256 0 -448 0 240 0 -40 0 1

11   Pass
n = 9; P_correct = [512 0 -1024 0 672 0 -160 0 10 0]; assert(isequal(chebyshev2ndKindPoly(n),P_correct));

A = 1×3 cell array {[1]} {1×2 double} {1×3 double} A = 1×4 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} A = 1×5 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} A = 1×6 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} A = 1×7 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} A = 1×8 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} A = 1×9 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} {1×9 double} A = 1×10 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} {1×9 double} {1×10 double} A = 1×11 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} {1×9 double} {1×10 double} {1×11 double} ans = 512 0 -1024 0 672 0 -160 0 10 0

12   Pass
n = 10; P_correct = [1024 0 -2304 0 1792 0 -560 0 60 0 -1]; assert(isequal(chebyshev2ndKindPoly(n),P_correct));

A = 1×3 cell array {[1]} {1×2 double} {1×3 double} A = 1×4 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} A = 1×5 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} A = 1×6 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} A = 1×7 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} A = 1×8 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} A = 1×9 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} {1×9 double} A = 1×10 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} {1×9 double} {1×10 double} A = 1×11 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} {1×9 double} {1×10 double} {1×11 double} A = 1×12 cell array Columns 1 through 11 {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} {1×9 double} {1×10 double} {1×11 double} Column 12 {1×12 double} ans = 1024 0 -2304 0 1792 0 -560 0 60 0 -1

13   Pass
n = 11; P_correct = [2048 0 -5120 0 4608 0 -1792 0 280 0 -12 0]; assert(isequal(chebyshev2ndKindPoly(n),P_correct));

A = 1×3 cell array {[1]} {1×2 double} {1×3 double} A = 1×4 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} A = 1×5 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} A = 1×6 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} A = 1×7 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} A = 1×8 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} A = 1×9 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} {1×9 double} A = 1×10 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} {1×9 double} {1×10 double} A = 1×11 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} {1×9 double} {1×10 double} {1×11 double} A = 1×12 cell array Columns 1 through 11 {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} {1×9 double} {1×10 double} {1×11 double} Column 12 {1×12 double} A = 1×13 cell array Columns 1 through 11 {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} {1×9 double} {1×10 double} {1×11 double} Columns 12 through 13 {1×12 double} {1×13 double} ans = 2048 0 -5120 0 4608 0 -1792 0 280 0 -12 0

14   Pass
n = 12; P_correct = [4096 0 -11264 0 11520 0 -5376 0 1120 0 -84 0 1]; assert(isequal(chebyshev2ndKindPoly(n),P_correct));

A = 1×3 cell array {[1]} {1×2 double} {1×3 double} A = 1×4 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} A = 1×5 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} A = 1×6 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} A = 1×7 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} A = 1×8 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} A = 1×9 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} {1×9 double} A = 1×10 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} {1×9 double} {1×10 double} A = 1×11 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} {1×9 double} {1×10 double} {1×11 double} A = 1×12 cell array Columns 1 through 11 {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} {1×9 double} {1×10 double} {1×11 double} Column 12 {1×12 double} A = 1×13 cell array Columns 1 through 11 {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} {1×9 double} {1×10 double} {1×11 double} Columns 12 through 13 {1×12 double} {1×13 double} A = 1×14 cell array Columns 1 through 11 {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} {1×9 double} {1×10 double} {1×11 double} Columns 12 through 14 {1×12 double} {1×13 double} {1×14 double} ans = 4096 0 -11264 0 11520 0 -5376 0 1120 0 -84 0 1

15   Pass
n = 13; P_correct = [8192 0 -24576 0 28160 0 -15360 0 4032 0 -448 0 14 0]; assert(isequal(chebyshev2ndKindPoly(n),P_correct));

A = 1×3 cell array {[1]} {1×2 double} {1×3 double} A = 1×4 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} A = 1×5 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} A = 1×6 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} A = 1×7 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} A = 1×8 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} A = 1×9 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} {1×9 double} A = 1×10 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} {1×9 double} {1×10 double} A = 1×11 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} {1×9 double} {1×10 double} {1×11 double} A = 1×12 cell array Columns 1 through 11 {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} {1×9 double} {1×10 double} {1×11 double} Column 12 {1×12 double} A = 1×13 cell array Columns 1 through 11 {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} {1×9 double} {1×10 double} {1×11 double} Columns 12 through 13 {1×12 double} {1×13 double} A = 1×14 cell array Columns 1 through 11 {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} {1×9 double} {1×10 double} {1×11 double} Columns 12 through 14 {1×12 double} {1×13 double} {1×14 double} A = 1×15 cell array Columns 1 through 11 {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} {1×9 double} {1×10 double} {1×11 double} Columns 12 through 15 {1×12 double} {1×13 double} {1×14 double} {1×15 double} ans = 8192 0 -24576 0 28160 0 -15360 0 4032 0 -448 0 14 0

16   Pass
n = 14; P_correct = [16384 0 -53248 0 67584 0 -42240 0 13440 0 -2016 0 112 0 -1]; assert(isequal(chebyshev2ndKindPoly(n),P_correct));

A = 1×3 cell array {[1]} {1×2 double} {1×3 double} A = 1×4 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} A = 1×5 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} A = 1×6 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} A = 1×7 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} A = 1×8 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} A = 1×9 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} {1×9 double} A = 1×10 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} {1×9 double} {1×10 double} A = 1×11 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} {1×9 double} {1×10 double} {1×11 double} A = 1×12 cell array Columns 1 through 11 {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} {1×9 double} {1×10 double} {1×11 double} Column 12 {1×12 double} A = 1×13 cell array Columns 1 through 11 {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} {1×9 double} {1×10 double} {1×11 double} Columns 12 through 13 {1×12 double} {1×13 double} A = 1×14 cell array Columns 1 through 11 {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} {1×9 double} {1×10 double} {1×11 double} Columns 12 through 14 {1×12 double} {1×13 double} {1×14 double} A = 1×15 cell array Columns 1 through 11 {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} {1×9 double} {1×10 double} {1×11 double} Columns 12 through 15 {1×12 double} {1×13 double} {1×14 double} {1×15 double} A = 1×16 cell array Columns 1 through 11 {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} {1×9 double} {1×10 double} {1×11 double} Columns 12 through 16 {1×12 double} {1×13 double} {1×14 double} {1×15 double} {1×16 double} ans = 16384 0 -53248 0 67584 0 -42240 0 13440 0 -2016 0 112 0 -1

17   Pass
n = 15; P_correct = [32768 0 -114688 0 159744 0 -112640 0 42240 0 -8064 0 672 0 -16 0]; assert(isequal(chebyshev2ndKindPoly(n),P_correct));

A = 1×3 cell array {[1]} {1×2 double} {1×3 double} A = 1×4 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} A = 1×5 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} A = 1×6 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} A = 1×7 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} A = 1×8 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} A = 1×9 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} {1×9 double} A = 1×10 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} {1×9 double} {1×10 double} A = 1×11 cell array {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} {1×9 double} {1×10 double} {1×11 double} A = 1×12 cell array Columns 1 through 11 {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} {1×9 double} {1×10 double} {1×11 double} Column 12 {1×12 double} A = 1×13 cell array Columns 1 through 11 {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} {1×9 double} {1×10 double} {1×11 double} Columns 12 through 13 {1×12 double} {1×13 double} A = 1×14 cell array Columns 1 through 11 {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} {1×9 double} {1×10 double} {1×11 double} Columns 12 through 14 {1×12 double} {1×13 double} {1×14 double} A = 1×15 cell array Columns 1 through 11 {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} {1×9 double} {1×10 double} {1×11 double} Columns 12 through 15 {1×12 double} {1×13 double} {1×14 double} {1×15 double} A = 1×16 cell array Columns 1 through 11 {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} {1×9 double} {1×10 double} {1×11 double} Columns 12 through 16 {1×12 double} {1×13 double} {1×14 double} {1×15 double} {1×16 double} A = 1×17 cell array Columns 1 through 11 {[1]} {1×2 double} {1×3 double} {1×4 double} {1×5 double} {1×6 double} {1×7 double} {1×8 double} {1×9 double} {1×10 double} {1×11 double} Columns 12 through 17 {1×12 double} {1×13 double} {1×14 double} {1×15 double} {1×16 double} {1×17 double} ans = Columns 1 through 15 32768 0 -114688 0 159744 0 -112640 0 42240 0 -8064 0 672 0 -16 Column 16 0