AJ Design Engineering Software Home Page
  Home    Page 2    Page 3    Page 4    Page 5    Physics    Math    Fluid Mechanics    Investment Finance     Loan Calculator     Nursing Math



AJ PHP Software Source Code Statistics Library
Binomial Coefficient


number binomial_coefficient ( integer, integer)

Description:

binomial_coefficient returns the binomial coefficient given n, possibilities, and k, unordered outcomes.

binomial coefficient

Source Code:

function binomial_coefficient ($n, $k)
{
  //variable and initializations
  $the_result = 0;
  $n_factorial = 0;
  $k_factorial = 0;
  $n_k_factorial = 0;

  //calculate n,k n-k factorial
  $n_factorial = factorial_integer($n);
  $k_factorial = factorial_integer($k);
  $n_k_factorial = factorial_integer($n - $k);

  if ($n_factorial != "error" and
      $k_factorial != "error" and
      $n_k_factorial != "error")
  {
    $the_result = $n_factorial / ($k_factorial * $n_k_factorial);
  }
  else
  {
    return "error";
  }

  return $the_result;
}

function factorial_integer ($k)
{
  //variable and initializations
  $the_result = 1;

  //check to see if k is an integer
  if (!is_int($k))
  {
    return "error";
  }

  //check for k < 0
  if ($k < 0)
  {
    return "error";
  }

  //0! = 1
  if ($k == 0)
  {
    return 1;
  }

  //calculate the result
  for ($i = 2; $i <= $k; $i++)
  {
    $the_result = $the_result * $i;
  }

  //return the value
  return $the_result;
}

Example:

<?
include ("ajstatistics.php");
$n = 6;
$k = 3;

$the_binomial_coefficient = binomial_coefficient($n, $k);

echo "n = $n<br>";
echo "k = $k<br>";
echo "the_binomial_coefficient = $the_binomial_coefficient<br>";
?>


Run Example


binomial coefficient binomial coefficient
mean mean of a set of number
median median of a set of number
standard deviation population standard deviation of a population
standard deviation sample standard deviation of a sample
variance population variance of a population
variance sample variance of a sample

References - Books:


Subwoofer Box Software Downloads for Sealed, Ported and Bandpass
Salary Wage Pay Calculator - Jobs Career
Baby Infant Growth Charts - Weight Age Percentile
Engine Horsepower Calculator
Earned Value Project Management
Present Worth Economics Calculator
Constant Acceleration Motion Calculator
Statistics Equations Formula Calculator
Mortgage Payment Finance Calculator
Weight Loss Formulas Calculator
Body Mass Index BMI Calculator
RGB Color Code Conversion Tool
Dog Age Calculator - How Old is Your Pet In Human Years?
Fluorescent Light Bulb Cost Analysis Calculator
Automobile Fuel Economy Calculator
Gasoline Diesel

Car Truck Tire Size Comparison Calculator

AJ Design - Online Science Mathematics Engineering Software Programs | 2 | 3 | 4 | 5

Technical Tools, Specifications, How to Guides, Applications, Examples, Tutorials, Answers, Resources, Analysis, Homework Solutions, Help, Data and Information for Engineers, Technicians, Teachers, Researchers, K-12 Education, College and High School Students and Scientists

contact email

Privacy Policy, Disclaimer and Terms

Copyright 2002-2007