logo for matrixlab-examples.com
[?] Subscribe To This Site

XML RSS
Add to Google
Add to My Yahoo!
Add to My MSN
Subscribe with Bloglines


Home
Matrixmania Blog
Contact
-> Sitemap <-
Matlab Books
Quick Matlab Guide
Matlab Tutorials
Matlab Examples
Matlab Flow Control
Boolean Algebra
Linear Algebra
Matlab 2D Plots
Matlab 3D Plots
Matlab GUI
Matlab Cookbook I
Matlab Cookbook II
Probability and Stats
Forums and Help
Relevant Links
Fun!
Your own Website?
Terms/Policies
leftimage for matrixlab-examples.com

Permutations and Combinations

This algorithm (program in Matlab) calculates the number of permutations and combinations of N objects taken D at a time.

The full Matlab code is:

% Clears variables and screen
clear; clc 

% Asks user for input
n = input('Total number of objects: ');
d = input(
'Size of subgroup: ');

% Computes and displays permut. according to basic formulas
p = 1;
for i = n - d + 1 : n
    p = p*i;

end
str1 = [num2str(p) ' permutations'];
disp(str1) 

% Computes and displays combin. according to basic formulas
str2 = [num2str(p/factorial(d)) ' combinations'];
disp(str2)

Example 1:


How many permut. and combin. can be made of the 26 letters of the alphabet, taking five at a time?

We run the code above and enter:

Total number of objects: 26
Size of subgroup: 5

The answer is:

7893600 permutations
65780 combinations

Example 2:


How many different ways can 12 computers be repaired if the workshop can only support 2 at a time?

We run the Matlab m-file above and enter:

Total number of objects: 12
Size of subgroup: 2

The answer (with no doubt) is:

132 permutations

66 combinations

From 'Permutations and Combinations' to home
From 'Permutations and Combinations' to 'Probability and Stats'


footer for permutations and combinations page