function coef = binomial_table ( qs, m, n ) %% BINOMIAL_TABLE computes a table of bionomial coefficients MOD QS. % % Discussion: % % For "technical reasons", COEF(0,0) is set to 0 instead of 1. % % Because MATLAB can't handle zero indices, MATLAB must refer to % COEF(I+1,J+1) when we really mean COEF(I,J). % % Modified: % % 09 June 2007 % % Author: % % John Burkardt % % Parameters: % % Input, integer QS, the base for the MOD operation. % % Input, integer M, N, the limits of the binomial table. % % Output, integer COEF(0:M,0:N), the table of binomial coefficients % modulo QS. % coef = zeros ( m+1, n+1 ); coef(2:m+1,1) = 1; for j = 1 : min ( m, n ) coef(j+1,j+1) = 1; end for j = 1 : n for i = j + 1 : m coef(i+1,j+1) = mod ( coef(i,j+1) + coef(i,j), qs ); end end