Reusable formula for decrementing denominator

  • Thread starter KevinMulito
  • Start date
  • Tags
    Formula
In summary: He is looking for a way to simplify his code and wonders if there is a consistent relationship between each fraction. However, the relationship is nonlinear and the only way to find the next fraction is by adding 1 to the denominator of the previous fraction. In summary, Fred is using a loop to calculate the sum of fractions and is looking for a way to simplify his code, but the relationship between each fraction is nonlinear.
  • #1
KevinMulito
1
0
I am currently working on computer program that has to find the sum of during looping:

1 + 1/2 + 1/3 + 1/4 + etc.

So the loop looks something like this:

sum = 1;
counter = 2;

while(...){
sum = sum + (1/counter);
counter = counter +1;
}

My general question however is purely mathematical.

I am currently using a basic counter variable to keep track of what the next denominator value will be, but I was hoping there was some formula I could be used to go from: 1/2 to 1/3, then 1/3 to 1/4. I am unable to find a consistent relationship between each value and the next in order to simplify my code. Any suggestions would be greatly appreciated.
 
Mathematics news on Phys.org
  • #2
The relationship is nonlinear -- you can't find a common difference or ratio between each pair of adjacent terms. The relationship is as follows: if the term in question is [itex]1 \over n[/itex], then the following term will be [itex]1 \over n + 1[/itex]. It's not really like you can add or multiply some constant to get the next term in the sequence.
 
  • #3
What he said. Looks like you're using JavaScript or similar, so you can sacrifice some readability and shorten it to
Code:
sum = 1;
counter = 2;

while(...){
sum = sum + (1/counter++);
}
The trailing ++ tells the compiler to add 1 to counter after the expression has been evaluated. That's about as simple as this code can get.

Fred
 

FAQ: Reusable formula for decrementing denominator

What is a reusable formula for decrementing denominator?

A reusable formula for decrementing denominator is a mathematical equation that can be used to decrease the value of a denominator in a fraction. It is often used in algebraic expressions or equations.

How do you use the reusable formula for decrementing denominator?

To use the reusable formula for decrementing denominator, you simply plug in the current value of the denominator into the equation and solve for the new value. This new value can then be used in place of the original denominator in your fraction.

What are the benefits of using a reusable formula for decrementing denominator?

One benefit of using a reusable formula for decrementing denominator is that it can save time and effort in mathematical calculations. It can also make solving algebraic equations with fractions easier and more efficient.

Are there any limitations to the reusable formula for decrementing denominator?

Yes, there are some limitations to the reusable formula for decrementing denominator. It may not work for all types of fractions, such as those with variables in both the numerator and denominator. It also may not be applicable in certain advanced mathematical concepts.

Can the reusable formula for decrementing denominator be used in other areas of mathematics?

Yes, the reusable formula for decrementing denominator can be applied in various fields of mathematics, such as algebra, calculus, and statistics. It can also be used in real-life situations, such as in financial calculations or data analysis.

Similar threads

Replies
7
Views
2K
Replies
20
Views
2K
Replies
10
Views
561
Replies
1
Views
1K
Replies
2
Views
2K
Replies
8
Views
2K
Replies
3
Views
1K
Replies
31
Views
2K
Replies
5
Views
1K
Back
Top