This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
AndreWalia's profile picture

Math Question

Started by AndreWalia, 22 February 2015 - 08:40 PM
AndreWalia #1
Posted 22 February 2015 - 09:40 PM
I think solving this will be pretty advanced….
Anyways
I wrote the following code:

function limit(zz)
  aa=0
  for bb=2,zz do
    aa=aa+(1/(bb-1))
  end
  return aa
end

And I was wondering,
What is the limit for aa?

I spent 30 mins of machine time to compute limit(10000000) and it was 16.695311265857.

I was wondering what limit(infinity) would be?
I know any machine would take a hecka long time to figure that out (infinity to be exact) but humans can solve equations and limits.
So is anyone up to the task?
This isn't my homework, I'm just bored.
Geforce Fan #2
Posted 23 February 2015 - 12:37 AM
theoretically, from my glance, the limit is infinity.
although, what you've done kinda breaks math… 1 over infinity… xD
Edited on 22 February 2015 - 11:38 PM
Dragon53535 #3
Posted 23 February 2015 - 12:54 AM
I'm confused how it took you 30 minutes to compute that, unless you were running it in CC. This code takes ~10 seconds to complete at 10 million, the same you did for 30 minutes.
AndreWalia #4
Posted 23 February 2015 - 01:02 AM
I was making it display the percentage of computations that are done every calculation
and i didnt use locals.

After I posted the OP I then made it display percentages every 10000 operations

theoretically, from my glance, the limit is infinity.
although, what you've done kinda breaks math… 1 over infinity… xD

How does this Equal infinity+1? Heck, from what I see, Its not over 100.
Dog #5
Posted 23 February 2015 - 01:27 AM
FWIW, I *think* GeforceFan meant 1 over infinity as in '1 / infinity', not 'infinity + 1'.

EDIT: spelling correction
Edited on 23 February 2015 - 12:33 AM
Dragon53535 #6
Posted 23 February 2015 - 01:28 AM
To be entirely technical, your calculation is actually to infinity - 1 since you start at 2. The best bet to get to the actual end with the number would be zz + 1
Bomb Bloke #7
Posted 23 February 2015 - 02:30 AM
theoretically, from my glance, the limit is infinity.
although, what you've done kinda breaks math… 1 over infinity… xD

As x nears infinity, 1 over x nears 0. Granted, no matter how many times the loop iterates, you'll never reach a number of infinite size, so you'll always be adding something - but the numbers get so small that the actual limit of the function will be lower than infinity, because you reach the point where you're no longer ever adding enough to reach to the next whole number.

Generally, this type of problem is solved by running the function a few times with various variables, then plotting the results on a graph. Examining the slope of the line gives you a pretty good indication as to where the output would stop getting any higher.
AndreWalia #8
Posted 23 February 2015 - 03:37 AM
I excluded 1 because the output would be infinity
Lyqyd #9
Posted 23 February 2015 - 05:58 AM
Well, if someone wants to play around with the plotting thing, I did happen to leave it running for a while, here are two data points:


> print(limit(100000000))
18.997896403853
> print(limit(100000000000))
25.905651686526
dan200 #10
Posted 23 February 2015 - 07:48 AM
This is a pretty classical calculus problem.
The question can be restated as: "What is the Sum from 2 to Infinity of '1/(X-1)'?"
Which can be simplified to: "What is the Sum from 1 to Infinity of '1/X'?", which we can solve by Integrating 1/X.
The integral of 1/X is Ln(x), which has no limit. So there's your answer.

Some googling revealed that this series has a name: the Harmonic Series, and has a few interesting properties.
Geforce Fan #11
Posted 26 February 2015 - 10:55 PM
theoretically, from my glance, the limit is infinity.
although, what you've done kinda breaks math… 1 over infinity… xD
This is a pretty classical calculus problem.
The question can be restated as: "What is the Sum from 2 to Infinity of '1/(X-1)'?"
Which can be simplified to: "What is the Sum from 1 to Infinity of '1/X'?", which we can solve by Integrating 1/X.
The integral of 1/X is Ln(x), which has no limit. So there's your answer.

Some googling revealed that this series has a name: the Harmonic Series, and has a few interesting properties.
Yes! I'm right!