Calc. No. of Partitions w/ Euler Formula

  • MATLAB
  • Thread starter richieec
  • Start date
  • Tags
    partitions
In summary, the conversation was about a program to calculate the number of partitions of a given number using Euler's formula. The program was shared, but the expert noticed some issues with the code and provided a modified version. The modifications included considering values of k from 1 to n/2, updating the value of fn correctly, and adding a base case for negative values of n. The expert encouraged the individual to keep working on the program and offered to answer any further questions.
  • #1
richieec
2
0
This program have to calculate the numbers of partitions of a number using the euler formula
So, here is the program i have done, i don't know where is the mistakes, and I would greatly appreciate to help me.
http://mathworld.wolfram.com/PartitionFunctionP.html#eqn11

Code:
function fn = euler(n)

if n == 0
    fn = 1;
    return
else
    for i = 1 : 1 : n
    fn = ((-1)^ (i + 1)) * euler(n - i * (3 * i - 1) / 2 ) + euler(n - i * (3 * i + 1 ) / 2);
    return
     end
  end
end
 
Last edited by a moderator:
Physics news on Phys.org
  • #2


Thank you for sharing your program! I can see that you are trying to use the Euler's formula for calculating the number of partitions of a given number. However, I noticed a few issues with your code.

Firstly, the formula for calculating the number of partitions using Euler's formula is:

P(n) = sum ( (-1)^k * (P(n - k(3k - 1) / 2) + P(n - k(3k + 1) / 2)), k = 1 to n )

In your code, you are only considering values of k from 1 to n, instead of 1 to n/2 as per the formula. This may result in incorrect calculations.

Secondly, in your for loop, you are reassigning the value of fn in each iteration, which is not correct. The value of fn should be updated by adding the calculated term in each iteration.

Lastly, your base case for n = 0 is correct, but you also need to consider the case when n is negative. In that case, the number of partitions is 0.

I have made some modifications to your code, please see below:

function fn = euler(n)

if n == 0
fn = 1;
return
elseif n < 0
fn = 0;
return
else
fn = 0;
for k = 1 : 1 : n/2
fn = fn + ((-1)^k) * (euler(n - k*(3*k - 1)/2) + euler(n - k*(3*k + 1)/2));
end
end

I hope this helps! Please let me know if you have any further questions. Keep up the good work!
 

1. What is the Euler Formula and how does it relate to calculating the number of partitions?

The Euler Formula is a mathematical equation that is used to calculate the number of partitions of a given number. It states that the number of partitions of a positive integer n is equal to the sum of the number of partitions of n-1 and the number of partitions of n-2.

2. What is the significance of calculating the number of partitions?

Calculating the number of partitions is useful in various fields such as combinatorics, number theory, and computer science. It helps in solving problems related to counting and enumeration, and also has applications in areas such as cryptography and coding theory.

3. How can the number of partitions be calculated using the Euler Formula?

The number of partitions can be calculated using the Euler Formula by recursively applying the formula for smaller values of n until the base cases of n=1 and n=2 are reached. The final result will be the number of partitions for the given number n.

4. Are there any other methods for calculating the number of partitions?

Yes, there are other methods for calculating the number of partitions such as using generating functions, Ferrers diagrams, and Young tableaux. These methods may be more efficient for certain values of n, but the Euler Formula is a general formula that can be applied to any positive integer.

5. Can the Euler Formula be extended to calculate the number of partitions for negative integers or non-integer values?

No, the Euler Formula is only applicable for calculating the number of partitions for positive integers. There are other formulas and methods for calculating the number of partitions for negative integers or non-integer values, but they are not based on the Euler Formula.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • Classical Physics
Replies
3
Views
599
Replies
1
Views
360
  • Precalculus Mathematics Homework Help
Replies
17
Views
1K
  • Quantum Physics
Replies
9
Views
780
  • General Math
Replies
1
Views
2K
  • Introductory Physics Homework Help
Replies
17
Views
588
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
1K
Replies
2
Views
1K
Back
Top