|
Post by tenochtitlanuk on Nov 9, 2021 9:39:44 GMT -5
Anyone looking for a bit of coding fun might like to try Harmonic Series on Rosetta Code. Calculate the sum of the reciprocals of the first n natural numbers Hn = 1 + 1/2 + 1/3 + ... + 1/nEasy with LB. Try it and then take advantage of LB's number ( or string) handling qualities to display more precision. Don't look at Diga Me until you've tried it!
|
|
|
Post by tsh73 on Nov 9, 2021 12:22:29 GMT -5
Isn't it not converging in mathematical sense?
yes, task kind of uses that
|
|
|
Post by tenochtitlanuk on Nov 9, 2021 14:58:57 GMT -5
I've had fun before with high-precision arithmetic. See High Precision on my site. Series where the sign of each term alternates +/- are not so immediately obvious... Clearly anything where you keep adding is going to be unbounded. See my quoted page and the line 'The harmonic series is divergent, albeit quite slowly, and grows toward infinity.'
The interest is in seeing the total reaching two digit numbers and more in finite computing time.
|
|
|
Post by tsh73 on Nov 9, 2021 15:13:13 GMT -5
Really it goes to 10 pretty fast. If we don't use function which calculates from 0 each time, that is
|
|
|
Post by tenochtitlanuk on Nov 9, 2021 17:21:45 GMT -5
Yup, it IS quite fast! What I found most interesting is LB's performance in terms of precision. If you specify 'print using( "##.#######################", h), you can see it is expressing wrongly the least significant figures, but internally representing them precisely. Hence by working backwards from the result you get back to EXACTLY 1!
The first twenty harmonic numbers are: 0.99999999999999991611392 by adding 0.99999999999999991611392 1.49999999999999987417088 by adding 0.49999999999999995805696 1.83333333333333289992192 by adding 0.33333333333333327740928 2.08333333333333296283648 by adding 0.24999999999999997902848 2.28333333333333287895040 by adding 0.20000000000000000000000 2.44999999999999947571200 by adding 0.16666666666666663870464 2.59285714285714212913152 by adding 0.14285714285714284216320 2.71785714285714232836096 by adding 0.12499999999999998951424 2.82896825396825350471680 by adding 0.11111111111111109246976 2.92896825396825346277376 by adding 0.10000000000000000000000 3.01987734487734442524672 by adding 0.09090909090909089955840 3.10321067821067789139968 by adding 0.08333333333333331935232 3.18013375513375467896832 by adding 0.07692307692307692388352 3.25156232656232650899456 by adding 0.07142857142857142108160 3.31822899322899314769920 by adding 0.06666666666666665967616 3.38072899322899324731392 by adding 0.06249999999999999475712 3.43955252264075765219328 by adding 0.05882352941176469848064 3.49510807819631307259904 by adding 0.05555555555555554623488 3.54773965714368178946048 by adding 0.05263157894736841277440 3.59773965714368160071680 by adding 0.05000000000000000000000
3.547739657143682 by subtracting 0.05000000000000000000000 3.495108078196313 by subtracting 0.05263157894736841277440 3.439552522640758 by subtracting 0.05555555555555554623488 3.380728993228994 by subtracting 0.05882352941176469848064 3.318228993228994 by subtracting 0.06249999999999999475712 3.251562326562327 by subtracting 0.06666666666666665967616 3.180133755133755 by subtracting 0.07142857142857142108160 3.103210678210678 by subtracting 0.07692307692307692388352 3.019877344877345 by subtracting 0.08333333333333331935232 2.928968253968254 by subtracting 0.09090909090909089955840 2.828968253968254 by subtracting 0.10000000000000000000000 2.717857142857143 by subtracting 0.11111111111111109246976 2.592857142857143 by subtracting 0.12499999999999998951424 2.450000000000000 by subtracting 0.14285714285714284216320 2.283333333333333 by subtracting 0.16666666666666663870464 2.083333333333333 by subtracting 0.20000000000000000000000 1.833333333333333 by subtracting 0.24999999999999997902848 1.500000000000000 by subtracting 0.33333333333333327740928 1.000000000000000 by subtracting 0.49999999999999995805696 0.000000000000000 by subtracting 0.99999999999999991611392
|
|