Binomial coefficients with Matla
I need to compute binomial coefficients recursively with Matlab, like a choose k=a!/k!(a-k)! Below is what I have written to first compute the factorial and then to compute the coefficients using the factorial I wrote, but it does not work. Any help?
function fact=recfact(n)
n==1
fact=1;
fact=n*recFact(n-1);
end
function coef=coef(a,k)
coef=recfact(a)/(recfact(k)*recfact(a-k))
end
function fact=recfact(n)
n==1
fact=1;
fact=n*recFact(n-1);
end
function coef=coef(a,k)
coef=recfact(a)/(recfact(k)*recfact(a-k))
end
0
Comments
The statement n==1 in function recfact(n) does nothing. Since your recursion has no criteria for ending it will keep going forever.
-drasnor