⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bicoeff.m

📁 很多matlab的源代码
💻 M
字号:
function G = bicoeff(n,k,tol)
% BICOEFF Binomial coefficient.
%
%	X = BICOEFF(n,k,TOL) returns the binomial coeff. nCk = n!/[k!(n-k)!] 
%	TOL = required tolerance [Default: TOL = 2e-16].
%
%	NOTE: n and k must be integers with n >= k
%	n and must be THE SAME SIZE. If not, one of them must be a SCALAR
%
%	USAGE: To compute: 5C2, 7C3, 4C2 use bicoeff([5 7 4],[2 3 2]).
% 
%	BICOEFF (with no input arguments) invokes the following example:
%
%	% Compute the binomial coefficients 5C2, 7C2 and 4C2. 
%	% We have n = [5 7 4], k = [2 2 2]. Since all k values are equal, use
%         >>x = bicoeff([5 7 4],2)

% Version 1.0
% Ashok Ambardar, EE Dept. MTU, Houghton, MI 49931, USA
% e-mail: akambard@mtu.edu
% Copyright (c) 1993

if nargin==0,help bicoeff,disp('Strike a key to see results of the example')
pause,x=bicoeff([5 7 4],2),return,end

if nargin == 2,tol=2e-16;end
[m1,n1]=size(n);[mm,nn]=size(k);
if m1*n1==1,if mm*nn>1,n=n*ones(mm,nn);end,
elseif mm*nn==1,if m1*n1>1,k=k*ones(m1,n1);end
else
if m1~=mm | n1~=nn,error('Matrix dimensions must agree'),return,end
end
kn=k-n;
if any(kn(:)>0),error('Must use k<=n'),return,end
x=n+1;y=k+1;xy=n-k+1;[m1,n1]=size(x);
z=[x y xy];c=gmln(z);
G=exp(c(:,1:n1)-c(:,n1+1:2*n1)-c(:,2*n1+1:3*n1));
G=round(G);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -