?? binomial.m
字號:
function bc=binomial(top,bottom)
%Created by PJNahin for "Duelling Idiots"(6/3/98)
%BINOMIAL computes the binomial coefficient (top)
% (bottom)
%which is equal to: top!/((top-bottom)!(bottom)!).
%Both top and bottom must be non-negative integers
%with bottom <= top.
%
%
if top==0|top==1 %if top = 0 or 1 then
%top! = 1
num=1;
else
x=2:top; %otherwise form 2x3x...xtop
num=prod(x); %to get top!
end
if bottom==0|bottom==1 %ditto for bottom!
den1=1;
else
x=2:bottom;
den1=prod(x);
end
test=top-bottom;
if test==0|test==1 %ditto for (top-bottom)!
den2=1;
else
x=2:test;
den2=prod(x);
end
bc=(num/den1)/den2;
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -