Pascal matrix generation: Difference between revisions

no edit summary
(add RPL)
imported>Maxima enthusiast
No edit summary
Line 3,507:
But since the builtin function MatrixExp works by first computing eigenvalues this is
likely to be slower for large Pascal matrices
 
=={{header|Maxima}}==
Using built-in functions genmatrix and binomial
<syntaxhighlight lang="maxima">
/* Function that returns a lower Pascal matrix */
lower_pascal(n):=genmatrix(lambda([i,j],binomial(i-1,j-1)),n,n)$
 
/* Function that returns an upper Pascal matrix */
upper_pascal(n):=genmatrix(lambda([i,j],binomial(j-1,i-1)),n,n)$
 
/* Function that returns a symmetric Pascal matrix (the matricial multiplication of a lower and an upper of the same size) */
symmetric_pascal(n):=lower_pascal(n).upper_pascal(n)$
 
/* Test cases */
lower_pascal(5);
upper_pascal(5);
symmetric_pascal(5);
</syntaxhighlight>
{{out}}
<pre>
matrix(
[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]
)
 
matrix(
[1, 1, 1, 1, 1],
[0, 1, 2, 3, 4],
[0, 0, 1, 3, 6],
[0, 0, 0, 1, 4],
[0, 0, 0, 0, 1]
)
 
matrix(
[1, 1, 1, 1, 1],
[1, 2, 3, 4, 5],
[1, 3, 6, 10, 15],
[1, 4, 10, 20, 35],
[1, 5, 15, 35, 70]
)
</pre>
 
=={{header|Nim}}==