Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,3 @@
|
|||
>> nchoosek(5,3)
|
||||
ans =
|
||||
10
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
function r = binomcoeff1(n,k)
|
||||
r = diag(rot90(pascal(n+1))); % vector of all binomial coefficients for order n
|
||||
r = r(k);
|
||||
end;
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
function r = binomcoeff2(n,k)
|
||||
prod((n-k+1:n)./(1:k))
|
||||
end;
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
function r = binomcoeff3(n,k)
|
||||
m = pascal(max(n-k,k)+1);
|
||||
r = m(n-k+1,k+1);
|
||||
end;
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
function coefficients = binomialCoeff(n,k)
|
||||
|
||||
coefficients = zeros(numel(n),numel(k)); %Preallocate memory
|
||||
|
||||
columns = (1:numel(k)); %Preallocate row and column counters
|
||||
rows = (1:numel(n));
|
||||
|
||||
%Iterate over every row and column. The rows represent the n number,
|
||||
%and the columns represent the k number. If n is ever greater than k,
|
||||
%the nchoosek function will throw an error. So, we test to make sure
|
||||
%it isn't, if it is then we leave that entry in the coefficients matrix
|
||||
%zero. Which makes sense combinatorically.
|
||||
for row = rows
|
||||
for col = columns
|
||||
if k(col) <= n(row)
|
||||
coefficients(row,col) = nchoosek(n(row),k(col));
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end %binomialCoeff
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
>> binomialCoeff((0:5),(0:5))
|
||||
|
||||
ans =
|
||||
|
||||
1 0 0 0 0 0
|
||||
1 1 0 0 0 0
|
||||
1 2 1 0 0 0
|
||||
1 3 3 1 0 0
|
||||
1 4 6 4 1 0
|
||||
1 5 10 10 5 1
|
||||
|
||||
>> binomialCoeff([1 0 3 2],(0:3))
|
||||
|
||||
ans =
|
||||
|
||||
1 1 0 0
|
||||
1 0 0 0
|
||||
1 3 3 1
|
||||
1 2 1 0
|
||||
|
||||
>> binomialCoeff(3,(0:3))
|
||||
|
||||
ans =
|
||||
|
||||
1 3 3 1
|
||||
|
||||
>> binomialCoeff((0:3),2)
|
||||
|
||||
ans =
|
||||
|
||||
0
|
||||
0
|
||||
1
|
||||
3
|
||||
|
||||
>> binomialCoeff(5,3)
|
||||
|
||||
ans =
|
||||
|
||||
10
|
||||
Loading…
Add table
Add a link
Reference in a new issue