Adding series of fractions in an equation.

May 2010
4
0
Hey, I'm looking for some help creating an equation. It's possible that this isn't really possible, but I figure there are more clever people than I in here that could use a puzzle :). I know this could be done using calculus symbols, but this is for a PHP script so I am looking for a more efficient (and, if luck permits, simpler) equation.

Basically, I'm trying to add up the sum of 1 divided by every number between X an Y.
For instance, if X = 5 and Y = 10, this would add (1/5+1/6+1/7+1/8+1/9+1/10). I could simply make a recursive function, but if there is a simple way to do this it would be a lot more efficient (as the X and Y could theoretically get up in the thousands).

Is there a simple way to find this (preferable in a normal y = ?x kind of equation -- though logs, exponents and other things like that are fine)?

Thanks!
- Submerged

P.S. If this belongs in a different thread, I'm sorry :). This could be answered via calc, but I figured looking for a simpler answer meant going to a simpler forum.
 

dwsmith

MHF Hall of Honor
Mar 2010
3,093
582
Florida
Hey, I'm looking for some help creating an equation. It's possible that this isn't really possible, but I figure there are more clever people than I in here that could use a puzzle :). I know this could be done using calculus symbols, but this is for a PHP script so I am looking for a more efficient (and, if luck permits, simpler) equation.

Basically, I'm trying to add up the sum of 1 divided by every number between X an Y.
For instance, if X = 5 and Y = 10, this would add (1/5+1/6+1/7+1/8+1/9+1/10). I could simply make a recursive function, but if there is a simple way to do this it would be a lot more efficient (as the X and Y could theoretically get up in the thousands).

Is there a simple way to find this (preferable in a normal y = ?x kind of equation -- though logs, exponents and other things like that are fine)?

Thanks!
- Submerged

P.S. If this belongs in a different thread, I'm sorry :). This could be answered via calc, but I figured looking for a simpler answer meant going to a simpler forum.
\(\displaystyle \sum_{n=1}^6\frac{1}{n+4}\)
 
May 2010
4
0
Thanks for the help, dwsmith, but is there anyway to do it without using calculus like that (i.e., a recursive summation)? I'm working with a PHP script on it, so I'm trying find a simpler equation (a y = ???x kind of deal) that would be more efficient for that code :).
 

dwsmith

MHF Hall of Honor
Mar 2010
3,093
582
Florida
Thanks for the help, dwsmith, but is there anyway to do it without using calculus like that (i.e., a recursive summation)? I'm working with a PHP script on it, so I'm trying find a simpler equation (a y = ???x kind of deal) that would be more efficient for that code :).
PHP?
 
May 2010
4
0
If you're asking what PHP is (hard to tell with just the question mark :)), it's a web programming language. It can do all the basic math functions (exponents, logs, etc.), and I can easily do what I'm trying here by calling a recursive that will simply do each part (1/2, 1/3, etc.) and then add them together, but that would be inefficent.
 

undefined

MHF Hall of Honor
Mar 2010
2,340
821
Chicago
Hey, I'm looking for some help creating an equation. It's possible that this isn't really possible, but I figure there are more clever people than I in here that could use a puzzle :). I know this could be done using calculus symbols, but this is for a PHP script so I am looking for a more efficient (and, if luck permits, simpler) equation.

Basically, I'm trying to add up the sum of 1 divided by every number between X an Y.
For instance, if X = 5 and Y = 10, this would add (1/5+1/6+1/7+1/8+1/9+1/10). I could simply make a recursive function, but if there is a simple way to do this it would be a lot more efficient (as the X and Y could theoretically get up in the thousands).

Is there a simple way to find this (preferable in a normal y = ?x kind of equation -- though logs, exponents and other things like that are fine)?

Thanks!
- Submerged

P.S. If this belongs in a different thread, I'm sorry :). This could be answered via calc, but I figured looking for a simpler answer meant going to a simpler forum.
Why would you use a recursive function when a simple loop would do?

PHP:
<?php
$y = 10;
$sum = 0;
for ($x = 5; $x <= $y; $x++)
  $sum += 1/$x;
echo $sum;
?>
As for whether there is a simple formula you could use, I don't know.

But how efficient do you need to be? Even with thousands of iterations, the above loop will execute in very little time.

By the way \(\displaystyle \sum\) is not a calculus symbol. No need to be afraid of it, it just means take the sum.
 
May 2010
4
0
True, I supposed a loop doesn't count as a recursive function :). If PHP can do it that quickly, then I can just leave it as it is -- I'm not as familiar with the power behind a server as most, all I know is how to write code.
 

undefined

MHF Hall of Honor
Mar 2010
2,340
821
Chicago
True, I supposed a loop doesn't count as a recursive function :). If PHP can do it that quickly, then I can just leave it as it is -- I'm not as familiar with the power behind a server as most, all I know is how to write code.
Yeah well 1 GHz means 1 billion cycles per second... there's a lot that can be done with speeds measured in GHz.