Code covered by the BSD License  

Highlights from
Subfactorial

Be the first to rate this file! 1 Download (last 30 days) File Size: 1.71 KB File ID: #24566

Subfactorial

by Yash

 

26 Jun 2009

Calculate subfactorial of integers up to 170.

| Watch this File

File Information
Description

Usage :
   r = subfactorial(n) calculates the subfactorial of a non -negative integer (n) using the inclusion-exclusion principle.
  The subfactorial can be written as,
      !n = n! sum( (-1)^k / k! ), for k = 0 to n
      !n : subfactorial(n)
      n! : factorial(n) = 1*2*3*...*n

Remark :
  This function is limited by largest floating point number that can be
  defined, as given by the realmax. Since,
      subfactorial(170) < realmax < subfactorial(171)
  Maximum value of input (n) cannot exceed 170.
  Higher value of (n) will return NaN.

Example:
  a = subfactorial(12);
  returns -> a = 176214841

See Also:
   factorial

MATLAB release MATLAB 6.0 (R12)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
subfactorial Yash 29 Jun 2009 10:42:08
mathematics Yash 29 Jun 2009 10:42:08
integer math Yash 29 Jun 2009 10:42:08
factorial Yash 29 Jun 2009 10:42:08
derangement Yash 29 Jun 2009 10:42:08
permutation Yash 29 Jun 2009 10:42:08

Contact us at files@mathworks.com