probabilities combinations - math

I faced a problem while writing a code in Matlab that calculates sum of products of all possible combinations of n numbers taken from a vector with length m. It is similar to the task that you will drag exactly n different balls out of the bag with m balls (order doesn't matter).
example:
m = 5, n = 3 then i need to calculate sum of 10 summands
thanks for your time

You should use nchoosek.
m=5;
n=3;
s=sum(nchoosek(1:m,n), 2);

Related

Problem similar to Coin change problem with finite coins, but with intervallic coin values and fixed number of coins

I have been struggling to create an algorithm, for a problem where we get an array of n coins with their max values. A coin in the array can have a value between 0 and this max value. We want to determine ALL permutations of possible order of coins given a sum target x. For example the array {2,2} with x = 3 has 2 permutations: 1+2, 2+1. I know this problem is related to coin change/knapsack/ sub-set problem. But haven't been able to make an algorithm based on these known solutions. I've tried doing dynamic programing, but all I could conclude that the array of possible targets is some kind of binomial. For example the array of coins with max values {3,3,3}, (n=3) can be any sum value from 0-9, where the number of permutations are:
sum value : permutations
0:1
1:3
2:6
3:10
4:12
5:12
6:10
7:6
8:3
9:1
From doing this I could atleast conclude that the the number of permutations for value 0 and max sum is always 1 and for value 1 and value max-1 is always n (length of the array). But I could not for the life of me figure out a recursion for the rest of the numbers, which is why I need help. Thanks in advance.

What's the probability that the distinct number appear in a size-k subset of n distinct number?

What's the probability that the distinct number appear in a size-k subset of n distinct numbers?
Let A be our target number, S be some the size-k subset of [1,2,3....n].
What's the probability that A is the one of k numbers in S? Many thanks.
PS: I can draw a condition tree diagram, and find the answer maybe the k/n.
But how can I think about it? Thanks again.
The probability is indeed, as you mentioned, k/n. Think about is this way: Let x be an element of [1,2,...,n]. There are binom(n,k) subsets of size k in total, and there are binom(n-1,k-1) subsets of size k that contain x (because x is chosen and we need to choose another k-1 elements). Hence the probability of x to be contained in S is binom(n-1,k-1)/binom(n,k)=k/n.

How to find number of way that a postage of n cents can be made by 4, 6, 10 cents?

For example,
n = 4 (4x1) 1 way
n = 10 (4x1, 6x1) (10x1) 2 ways
Is there any equation can express the number of way?
You have used recurrence-relation tag - yes, it is possible to use recurrence to calculate the number of ways.
P(N) = P(N-10) + P(N-6) + P(N-4)
P(0) = 1
Explanation - you can get sum N, using (N-10) cents sum and 10-cent coin and so on.
For rather large values of N recursive algorithm will work too long, so one could build dynamic programming algorithm to accelerate calculations (DP will reuse calculated values for smaller sums)
Suppose you have a list of denominations. In your case it is A = [4,6,10]. So suppose you have the following things:
A = [4,6,10]
Length of list A = N
Sum = K
The problem can be written as:
# Given the list of denominations, its length and the sum.
P(A,N,K) = 0 if N < 0 or K < 0,
1 if K = 0,
P(A,N-1,K) + P(A,N-1,k-A[N]) #A[N]-> Nth element of list
As we can see the possibility of re-using sub-problems, DP will work wonderfully.

finding the number of ways to generate a number

I am new to permutations and combinations. I am provided with the number n and I can make a number with the help of n+1 digits which are 0,1,...n. I need to find in how many ways I can make the sum n by putting these n+1 digits in n places.
Like i am having number n=2
then
(a) 0 and 2 (b)1 and 1 (c)2 and 0 .
for a number n=3
then
(a)0,0,3 (b)0,3,0 (c)3,0,0 (d)0,1,2 (e)0,2,1 (f)1,0,2 (g)1,2,0 (h)2,0,1 (i)2,1,0 (j)1,1,1
So in total i have 10 ways to generate sum=3 by using the digits 0,1,2,3.
And also consider i can put these n+1 digits in n places only.
The number of compositions of n into k nonnegative summands is (n+k-1) choose n by the stars-and-bars method. You have k=n, so the count is 2n-1 choose n. Your examples were 3C2=3 and 5C3=10.
Yes, the number of total ways for making the sum=n using n+1 digits is equal to (n+n-1)C(n-1) or you can say (n+n-1)C(n).

Stirling numbers of the second kind with multisets

I was looking at [Stirling numbers of the second kind], which are the total number of ways to split a set of length n into k non-empty subsets, where order does not matter.(http://mathworld.wolfram.com/StirlingNumberoftheSecondKind.html), and was wondering how to write a non-naive algorithm to compute
S(n, k {occurences of each element})
Where
S(6, 3, {1, 2, 3} )
would give the total number of ways a set with 6 elements in which 3 are the same element and a different 2 are another element (and 1 is its unique element) could be split into 3 non-empty sets, ignoring permutations.
There is a recursive formula for regular Stirling numbers of the second kind S(n, k), but unlikely to be a comparable function for multisets.
So what's an algorithm that could calculate this number?
Relevant question on Math.SE here, without a real method to calculate this number.

Resources