HP 12C Permutation and Combination
|
08-23-2017, 06:32 PM
(This post was last modified: 05-07-2018 08:28 PM by Dieter.)
Post: #22
|
|||
|
|||
RE: HP 12C Permutation and Combination
(08-23-2017 06:40 AM)Gamo Wrote: Your program is very nice and easy to use so I use it a lot and find out another problem with 60p5 this time the result show 655 381 440.2 on regular cheap Casio fx-260 solar gave result 655 381 440 Sure. As already explained (please read my previous posts again) this can and will happen if you calculate with factorials which cannot be represented exactly with 10 digits. (08-23-2017 06:40 AM)Gamo Wrote: Is it possible just to add INTG to the program? That's not a good idea. The error can be both positive and negative. If the result is a bit too small, INTG will be off by one (or even more). Just remember 25P7 on the Prime or any other correctly working 12-digit calculator (2422727999,99) resp. on the 10-digit 12C (2422727999). You could round the result by adding 0,5 first and then use INTG, but this does not mean that the result is exact – the error may be > 1. If you want to avoid or at least minimize this kind of error you have to do the calculation without factorials. I have described a way to do so and you'll also find an explanation why the preferable method avoids roundoff errors. Here are two programs that will do this job. First, here is a compact version that returns both nCr in X and nPr in Y. If you want to have it the other way round, simply swap the final RCL 3 and RCL 4. Code: 01 STO 0 25 [ENTER] 7 [R/S] => 480700 [x<>y] => 2422728000 This program should (usually) return accurate results if the latter can be respresented exactly with 10 digits. Second, here is a deluxe version that calculates nCr and nPr. A negative r yields nPr, a positive r gives nCr: 25 [ENTER] 7 [R/S] => 480700 25 [ENTER] -7 [R/S] => 2422728000 Code: 01 ENTER Ths program uses a trick (as proposed in the other thread I linked to earlier) to calculate nCr without overflow as long as the result does not exceed 9,999999999 E+99. Of course this also applies to nPr. There is no overflow unless the result overflows. Both programs will correctly return 60 P 5 = 655381440. This is because they do not work with factorials but with repeated multiplication. Just as probably all (or at least most) calculators do in their internal nPr and nCr functions. Of course this method is slower than calculating with factorials. But on a 12CP, let alone an emulator, this should not be an issue. Dieter |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)