There is no pascal function.
Reported by Michael BAUDIN
Originally assigned to Michael BAUDIN
-- Bug description --
There is no pascal function.
Matlab offers the pascal function :
http://www.mathworks.com/access/helpdesk/help/techdoc/ref/pascal.html
Various implementations were tested at :
http://forge.scilab.org/index.php/p/docintrodiscrprobas/source/tree/HEAD/en_US/introdiscreteprobas/scripts/pascal_triangle.sce
So far, the best implementations I found were the following.
These implementations avoid loops and are based on the nchoosek
function.
function c = pascallow (n)
N = tril((0:n-1)' * ones(1,n))
K = tril(((0:n-1)' * ones(1,n))')
c = zeros(n,n)
c(1:n,1) = 1
nz = find(N<>0 & K<>0)
if ( nz <> [] ) then
c(nz) = nchoosek (N(nz),K(nz))
end
endfunction
function P = pascalsym (n)
K = (0:n-1)' * ones(1,n)
N = K+K'
P = nchoosek (N,K)
endfunction
The upper triangular Pascal matrix can be computed with the single
quote :
pascallow(n)'
The following statements show that the previous implementations are
satisfying the equation S = L * U :
L = pascallow ( 5 );
U = L';
S = pascalsym ( 5 );
L * U - S
-- Scilab error message --
-- How to reproduce the bug --