Base of Natural Logarithms  Printable Version + HP Forums (https://archived.hpcalc.org/museumforum) + Forum: HP Museum Forums (https://archived.hpcalc.org/museumforum/forum1.html) + Forum: Old HP Forum Archives (https://archived.hpcalc.org/museumforum/forum2.html) + Thread: Base of Natural Logarithms (/thread121449.html) 
Base of Natural Logarithms  Vincze  08132007 Is there programmatic way to calculate the base of natural logarithms (or Euler Number) if the function of "e" were not available. I know what the formula is for "e", but how would one pro grammatically find this on say a 35s, or other similar calculator? Edited: 13 Aug 2007, 7:37 p.m.
Re: Base of Natural Logarithms  Brad Davis  08132007 Does the 35s not have e^x?
You could use a series expansion.
Re: Base of Natural Logarithms  Chuck  08132007 Do you want to have unlimited accuracy? or is this close enough?
848456353 That's close enough for most calculations.
Or use a simple loop to find the sum of 1/n! as n goes from 0, 20. This gives 2.7182818284590452353(39784). Edited: 13 Aug 2007, 8:41 p.m.
Re: Base of Natural Logarithms  Katie Wasserman  08132007 This is a pretty simple program to write, just a few lines. You can also compute it in the equation solver in several different ways. But it doesn't need to be computed at all on this machine, it's now in the constants menu.
Re: Base of Natural Logarithms  Thomas Klemm  08132007 On the 35s:
Just a few ideas.
Edited: 14 Aug 2007, 3:03 a.m.
Re: Base of Natural Logarithms (OT)  Chuck  08132007 Here's the problem I have with the programming required of some calculators. To do a loop from 1 to 20 of 1/n! stored in a register, this is the best I can come up with ...
This seems like a rediculous number of steps for a simple loop.
CHUCK
Re: Base of Natural Logarithms  Thomas Okken  08132007 Erm, I'm not sure if I understand what you're asking here. You say that you know the formula for e, but you can't figure out how to write a program to compute that value? e = 1 + 1/1 + 1/(1*2) + 1/(1*2*3) + 1/(1*2*3*4) + 1/(1*2*3*4*5) + ... Hint: if you number the terms like 0, 1, 2, 3, etc., then for all terms numbered 1 and greater, term n is a factor n smaller than the one before. Just keep summing until adding a term no longer changes your result; thanks to the limited precision of most calculators, that won't take long. If you're going to ask for an actual program, I'm going to start suspecting you're a student asking us to do your homework. ;)
 Thomas
Re: Base of Natural Logarithms (OT)  Paul Dale  08132007 One step less by running the loop backwards.
E001 LBL E
 Pauli
Re: Base of Natural Logarithms (OT)  Chuck  08132007 I now see that the STO+ was an unecessary step (since the values remain on the stack), but why would backwards be better numerically? Non comprendo.
Re: Base of Natural Logarithms (OT)  Paul Dale  08132007 It is more stable backwards because you're adding like sized terms the whole time and generally maintaining full precision as well. Going forwards starts with a 1 term and by the time you're near the end, most of the significant digits are beyond the precision of the sum. The difference will likely be at most a digit or two in the last place but it doesn't take any extra effort to work from the small terms to the large.
 Pauli
Re: Base of Natural Logarithms (OT)  Thomas Klemm  08142007 Use Horner's Method (p. 1326 in the User's Guide) to avoid factorial:
E001 LBL E
20 XEQ E001
Re: Base of Natural Logarithms  Thomas Klemm  08142007 Quote:
I've tried to solve the following equation: ABS(E^(Pi*i)+1)=0
I would have expected to get: NO ROOT FND
Instead I got: INVALID y^{x} Any ideas why?
It seems that somehow E becomes 0, though this case (i.e. 0 with complex exponent) isn't mentioned in the user's guide as a possible reason for that message.
However it works if 0 is replaced in the equation by 1E11.
Re: Base of Natural Logarithms  Vincze  08142007 I know it is on calculator, but I just curious how the program would be written.
Re: Base of Natural Logarithms  Vincze  08142007 But formula is lim n > infinity (1+1/n)^n. What I don't understand is how you deal with infinity. I guess you could loop a couple hundred times to deliver accuracy, but how was this calculated in past, when e not available.
I guess reason I ask is I try and better understand programming on HP calculator, so I thought this would be a good test to see how something like infinity be handled.
Re: Base of Natural Logarithms  Thomas Okken  08142007 Dealing with infinity can be tricky, and there is no one answer for all situations. In the case of the series for e, the key insight is that the terms get progressively smaller as n increases, and that in fact, they shrink so quickly that you only need to sum a few in order to reach maximum precision. 1/16! = 4.78e14, which is too small to affect the value of e when working with 12digit precision  so after summing only 16 terms, you're done. If you're working with higher precision, you'll need more terms, of course. You can work out in advance when the terms will become too small to affect the result any further, or you can simply compare each iteration's result to the previous one, and terminate the loop when there is no further change. And if you want the best possible accuracy, you can sum the series from smallest terms to largest (that requires working out which is the smallest term in advance), to minimize the effect of roundoff error on the final result. Note that the series for e (or generally speaking, for e^x, and the related series for sin and cos) have the nice property that the terms shrink very quickly, but this is not true for all series, like the notoriously useless tan(x) = 1  x/3 + x/5  x/7... In such cases you'll have to look for a more clever approach.
 Thomas
Re: Base of Natural Logarithms  Vincze  08142007 Okay, but how you write program to do this? I no student in school, but I am student of life, and want to learn how to do something like this. I try some programming but I still very green as you say in America, and still trying to grasp concept of RPN programming.
If this was in C, cobol, or assembler, I would know what to do, but I baffled with programming on 35s. Maybe it too simple and that my issue.
Re: Base of Natural Logarithms  Don Shepherd  08142007 Vincze, you need to get the museum DVD. It has the manuals of almost all HP calculators, and you need to read the programming sections of those manuals. That will teach you how to program in RPN.
Re: Base of Natural Logarithms  Vincze  08142007 But I have HP35s and its manual, but it not explain the programming and looping and loop testing, etc. If I want to loop something say 20 times, how would I control that in 35s and take final value and display? It talk about very little in manual. I have friend who has older version of CD's from here. What would be good manual to look at that explain this better than current 35s manual.
Re: Base of Natural Logarithms  Don Shepherd  08142007 Vincze, how can you say the 35s manual does not discuss programming and looping? Part 2 of the manual is about nothing but programming. Loops are described on pages 1416 to 1418. You really need to read these sections and play around with it.
Re: Base of Natural Logarithms  Lyuka  08142007 9242691/3400196 (within 7 digits, error < 9.4e14)
49171/18089 (within 16 bit, error < 1.02e10) Katie Wasserman's "buggy little beast" sigma function  Miguel Toro  08142007 You also could use this:
(IDIV(I,18)1)/A = (1IDIV(I,18))/A + 0*(E+1/I!STO E) + 0*(I+1STO I) or still:
(IDIV(I,18)1)/A = (1IDIV(I,18))/A + 0*(E/(20I)+1STO E) + 0*(I+1STO I) Just amazing! enjoy.
Miguel
