Jump to content

Pascal matrix generation: Difference between revisions

no edit summary
(Added Ada implementation)
No edit summary
Line 2,183:
1 5 15 35 70</pre>
 
=={{header|Maple}}==
<lang Maple>
PascalUT := proc(n::integer)
local M := Matrix(n,n):
local i:
local j:
M[1,1..n] := 1:
for j from 2 to n do
for i from 2 to n do
M[i,j] := M[i,j-1] + M[i-1,j-1]:
end:
end:
return M:
end proc:
 
PascalUT(5);
 
PascalLT := proc(n::integer)
local M := Matrix(n,n):
local i:
local j:
M[1..n,1] := 1:
for i from 2 to n do
for j from 2 to n do
M[i,j] := M[i-1,j] + M[i-1,j-1]:
end:
end:
return M:
end proc:
 
PascalLT(5);
 
Pascal := proc(n::integer)
local M := Matrix(n,n):
local i:
local j:
M[1..n,1] := 1:
M[1,2..n] := 1:
for i from 2 to n do
for j from 2 to n do
M[i,j] := M[i,j-1] + M[i-1,j]:
end:
end:
return M:
end proc:
 
Pascal(5);
 
</lang>
{{out}}<pre>
[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]
 
[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]
 
[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|Mathematica}}==
One solution is to generate a symmetric Pascal matrix then use the built in method to
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.