Pascal matrix generation: Difference between revisions

Added 11l
(Added Wren)
(Added 11l)
Line 44:
The   [[Cholesky decomposition]]   of a Pascal symmetric matrix is the Pascal lower-triangle matrix of the same size.
<br><br>
 
=={{header|11l}}==
{{trans|Python}}
 
<lang 11l>F pascal_upp(n)
V s = [[0] * n] * n
s[0] = [1] * n
L(i) 1 .< n
L(j) i .< n
s[i][j] = s[i - 1][j - 1] + s[i][j - 1]
R s
 
F pascal_low(n)
V upp = pascal_upp(n)
V s = [[0] * n] * n
L(x) 0 .< n
L(y) 0 .< n
s[y][x] = upp[x][y]
R s
 
F pascal_sym(n)
V s = [[1] * n] * n
L(i) 1 .< n
L(j) 1 .< n
s[i][j] = s[i - 1][j] + s[i][j - 1]
R s
 
F pp(mat)
print(‘[’mat.map(String).join(",\n ")‘]’)
 
-V n = 5
print(‘Upper:’)
pp(pascal_upp(n))
print("\nLower:")
pp(pascal_low(n))
print("\nSymmetric:")
pp(pascal_sym(n))</lang>
 
{{out}}
<pre>
Upper:
[[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]]
 
Lower:
[[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]]
 
Symmetric:
[[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|360 Assembly}}==
1,481

edits