[Scilab-users] Help about Scilab
Dang, Christophe
Christophe.Dang at sidel.com
Wed Feb 4 09:48:57 CET 2015
Hello,
> De : Pawel Postek
> Envoyé : mardi 3 février 2015 19:35
>
> c = nchoosek (n,m)
> I need to convert this code to Scilab.
> I'm trying to do this, but I fail.
The Mathworks page tells me that nchoosek () computes the binomial coefficient.
I suggest you read /Introduction to discrete probabilities in Scilab/
http://www.scilab.org/content/download/248/1706/file/introdiscreteprobas.pdf
section 2.10 " Computing combinations with Scilab" (p. 24-25) says
"There is no Scilab function to compute the binomial number"
And give the following solution :
// combinations --
// Returns the number of combinations of j objects chosen from n objects .
function c = combinations ( n , j )
c = exp( gammaln (n+1) - gammaln (j+1) - gammaln (n-j +1));
// If the input where integers , returns also an integer .
if ( and( round (n)==n) & and( round (j)==j) ) then
b = round ( b )
end
endfunction
Best regards
--
Christophe Dang Ngoc Chan
Mechanical calculation engineer
This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error), please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.
More information about the users
mailing list