Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Solution 237189

Submitted on 28 Apr 2013 by Paul Berglund

Correct

56Size
Leading solution size is 15.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test
Code Input and Output
1
Pass
 
%%
user_solution = fileread('pascalMat.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(pascalMat(n),P_correct));

                    
3
Pass
 
%%
n = 1;
P_correct = [
    1  0
    1  1
    ];
assert(isequal(pascalMat(n),P_correct));

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

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

                    
6
Pass
 
%%
n = 4;
P_correct = [
    1  0  0  0  0
    1  1  0  0  0
    1  2  1  0  0
    1  3  3  1  0
    1  4  6  4  1
    ];
assert(isequal(pascalMat(n),P_correct));

                    
7
Pass
 
%%
n = 5;
P_correct = [
    1   0   0   0   0   0
    1   1   0   0   0   0
    1   2   1   0   0   0
    1   3   3   1   0   0
    1   4   6   4   1   0
    1   5  10  10   5   1
    ];
assert(isequal(pascalMat(n),P_correct));

                    
8
Pass
 
%%
n = 6;
P_correct = [
    1   0   0   0   0   0   0
    1   1   0   0   0   0   0
    1   2   1   0   0   0   0
    1   3   3   1   0   0   0
    1   4   6   4   1   0   0
    1   5  10  10   5   1   0
    1   6  15  20  15   6   1
    ];
assert(isequal(pascalMat(n),P_correct));

                    
9
Pass
 
%%
n = 7;
P_correct = [
    1   0   0   0   0   0   0   0
    1   1   0   0   0   0   0   0
    1   2   1   0   0   0   0   0
    1   3   3   1   0   0   0   0
    1   4   6   4   1   0   0   0
    1   5  10  10   5   1   0   0
    1   6  15  20  15   6   1   0
    1   7  21  35  35  21   7   1
    ];
assert(isequal(pascalMat(n),P_correct));

                    
10
Pass
 
%%
n = 8;
P_correct = [
    1   0   0   0   0   0   0   0   0
    1   1   0   0   0   0   0   0   0
    1   2   1   0   0   0   0   0   0
    1   3   3   1   0   0   0   0   0
    1   4   6   4   1   0   0   0   0
    1   5  10  10   5   1   0   0   0
    1   6  15  20  15   6   1   0   0
    1   7  21  35  35  21   7   1   0
    1   8  28  56  70  56  28   8   1
    ];
assert(isequal(pascalMat(n),P_correct));

                    
11
Pass
 
%%
n = 9;
P_correct = [
    1    0    0    0    0    0    0    0    0    0
    1    1    0    0    0    0    0    0    0    0
    1    2    1    0    0    0    0    0    0    0
    1    3    3    1    0    0    0    0    0    0
    1    4    6    4    1    0    0    0    0    0
    1    5   10   10    5    1    0    0    0    0
    1    6   15   20   15    6    1    0    0    0
    1    7   21   35   35   21    7    1    0    0
    1    8   28   56   70   56   28    8    1    0
    1    9   36   84  126  126   84   36    9    1
    ];
assert(isequal(pascalMat(n),P_correct));

                    
12
Pass
 
%%
n = 10;
P_correct = [
    1    0    0    0    0    0    0    0    0    0    0
    1    1    0    0    0    0    0    0    0    0    0
    1    2    1    0    0    0    0    0    0    0    0
    1    3    3    1    0    0    0    0    0    0    0
    1    4    6    4    1    0    0    0    0    0    0
    1    5   10   10    5    1    0    0    0    0    0
    1    6   15   20   15    6    1    0    0    0    0
    1    7   21   35   35   21    7    1    0    0    0
    1    8   28   56   70   56   28    8    1    0    0
    1    9   36   84  126  126   84   36    9    1    0
    1   10   45  120  210  252  210  120   45   10    1
    ];
assert(isequal(pascalMat(n),P_correct));

                    
13
Pass
 
%%
n = 11;
P_correct = [
    1    0    0    0    0    0    0    0    0    0    0    0
    1    1    0    0    0    0    0    0    0    0    0    0
    1    2    1    0    0    0    0    0    0    0    0    0
    1    3    3    1    0    0    0    0    0    0    0    0
    1    4    6    4    1    0    0    0    0    0    0    0
    1    5   10   10    5    1    0    0    0    0    0    0
    1    6   15   20   15    6    1    0    0    0    0    0
    1    7   21   35   35   21    7    1    0    0    0    0
    1    8   28   56   70   56   28    8    1    0    0    0
    1    9   36   84  126  126   84   36    9    1    0    0
    1   10   45  120  210  252  210  120   45   10    1    0
    1   11   55  165  330  462  462  330  165   55   11    1
    ];
assert(isequal(pascalMat(n),P_correct));

                    
14
Pass
 
%%
n = 12;
P_correct = [
    1    0    0    0    0    0    0    0    0    0    0    0    0
    1    1    0    0    0    0    0    0    0    0    0    0    0
    1    2    1    0    0    0    0    0    0    0    0    0    0
    1    3    3    1    0    0    0    0    0    0    0    0    0
    1    4    6    4    1    0    0    0    0    0    0    0    0
    1    5   10   10    5    1    0    0    0    0    0    0    0
    1    6   15   20   15    6    1    0    0    0    0    0    0
    1    7   21   35   35   21    7    1    0    0    0    0    0
    1    8   28   56   70   56   28    8    1    0    0    0    0
    1    9   36   84  126  126   84   36    9    1    0    0    0
    1   10   45  120  210  252  210  120   45   10    1    0    0
    1   11   55  165  330  462  462  330  165   55   11    1    0
    1   12   66  220  495  792  924  792  495  220   66   12    1
    ];
assert(isequal(pascalMat(n),P_correct));

                    
15
Pass
 
%%
n = 13;
P_correct = [
    1     0     0     0     0     0     0     0     0     0     0     0     0     0
    1     1     0     0     0     0     0     0     0     0     0     0     0     0
    1     2     1     0     0     0     0     0     0     0     0     0     0     0
    1     3     3     1     0     0     0     0     0     0     0     0     0     0
    1     4     6     4     1     0     0     0     0     0     0     0     0     0
    1     5    10    10     5     1     0     0     0     0     0     0     0     0
    1     6    15    20    15     6     1     0     0     0     0     0     0     0
    1     7    21    35    35    21     7     1     0     0     0     0     0     0
    1     8    28    56    70    56    28     8     1     0     0     0     0     0
    1     9    36    84   126   126    84    36     9     1     0     0     0     0
    1    10    45   120   210   252   210   120    45    10     1     0     0     0
    1    11    55   165   330   462   462   330   165    55    11     1     0     0
    1    12    66   220   495   792   924   792   495   220    66    12     1     0
    1    13    78   286   715  1287  1716  1716  1287   715   286    78    13     1
    ];
assert(isequal(pascalMat(n),P_correct));

                    
16
Pass
 
%%
n = 14;
P_correct = [
    1              0              0              0              0              0              0              0              0              0              0              0              0              0              0
    1              1              0              0              0              0              0              0              0              0              0              0              0              0              0
    1              2              1              0              0              0              0              0              0              0              0              0              0              0              0
    1              3              3              1              0              0              0              0              0              0              0              0              0              0              0
    1              4              6              4              1              0              0              0              0              0              0              0              0              0              0
    1              5             10             10              5              1              0              0              0              0              0              0              0              0              0
    1              6             15             20             15              6              1              0              0              0              0              0              0              0              0
    1              7             21             35             35             21              7              1              0              0              0              0              0              0              0
    1              8             28             56             70             56             28              8              1              0              0              0              0              0              0
    1              9             36             84            126            126             84             36              9              1              0              0              0              0              0
    1             10             45            120            210            252            210            120             45             10              1              0              0              0              0
    1             11             55            165            330            462            462            330            165             55             11              1              0              0              0
    1             12             66            220            495            792            924            792            495            220             66             12              1              0              0
    1             13             78            286            715           1287           1716           1716           1287            715            286             78             13              1              0
    1             14             91            364           1001           2002           3003           3432           3003           2002           1001            364             91             14              1
    ];
assert(isequal(pascalMat(n),P_correct));

                    
17
Pass
 
%%
n = 15;
P_correct = [
    1              0              0              0              0              0              0              0              0              0              0              0              0              0              0              0
    1              1              0              0              0              0              0              0              0              0              0              0              0              0              0              0
    1              2              1              0              0              0              0              0              0              0              0              0              0              0              0              0
    1              3              3              1              0              0              0              0              0              0              0              0              0              0              0              0
    1              4              6              4              1              0              0              0              0              0              0              0              0              0              0              0
    1              5             10             10              5              1              0              0              0              0              0              0              0              0              0              0
    1              6             15             20             15              6              1              0              0              0              0              0              0              0              0              0
    1              7             21             35             35             21              7              1              0              0              0              0              0              0              0              0
    1              8             28             56             70             56             28              8              1              0              0              0              0              0              0              0
    1              9             36             84            126            126             84             36              9              1              0              0              0              0              0              0
    1             10             45            120            210            252            210            120             45             10              1              0              0              0              0              0
    1             11             55            165            330            462            462            330            165             55             11              1              0              0              0              0
    1             12             66            220            495            792            924            792            495            220             66             12              1              0              0              0
    1             13             78            286            715           1287           1716           1716           1287            715            286             78             13              1              0              0
    1             14             91            364           1001           2002           3003           3432           3003           2002           1001            364             91             14              1              0
    1             15            105            455           1365           3003           5005           6435           6435           5005           3003           1365            455            105             15              1
    ];
assert(isequal(pascalMat(n),P_correct));