Pascal's triangle: Difference between revisions
Content added Content deleted
(→{{header|MATLAB}} / {{header|Octave}}: Pascal matrix) |
(→{{header|MATLAB}} / {{header|Octave}}: extract binomial coefficients from Pascal triangle) |
||
Line 1,222: | Line 1,222: | ||
=={{header|MATLAB}} / {{header|Octave}}== |
=={{header|MATLAB}} / {{header|Octave}}== |
||
A matrix containing the pascal triangle can be obtained this way: |
|||
<lang MATLAB>pascal(n);</lang> |
<lang MATLAB>pascal(n);</lang> |
||
Line 1,235: | Line 1,236: | ||
</pre> |
</pre> |
||
The binomial coefficients can be extracted from the Pascal triangle in this way: |
|||
<lang MATLAB> binomCoeff = diag(rot90(pascal(n)))', </lang> |
|||
<pre>>> for k=1:6,diag(rot90(pascal(k)))', end |
|||
ans = 1 |
|||
ans = |
|||
1 1 |
|||
ans = |
|||
1 2 1 |
|||
ans = |
|||
1 3 3 1 |
|||
ans = |
|||
1 4 6 4 1 |
|||
ans = |
|||
1 5 10 10 5 1 |
|||
</pre> |
|||
=={{header|Metafont}}== |
=={{header|Metafont}}== |
||