From: Dima on 31 Jan 2010 16:54 I defined a function for calculating probabilities of Poisson distribution. When I try to calculate probability for large numbers using floating point format I get incorrect results. The file with screenshots is here: http://pics.livejournal.com/iosaaris/pic/0004w4hk.jpg The upper left screen shows how the function Poi() was defined. One below shows the calculation of Poi(300, 200). At first it is calculated symbolically and then the result is converted to floating point number. In this case the result is correct. My TI-89 gives the same result (two screenshots at right). When I try to calculate the same function using floating point numbers as input (lower left screen) I get significantly different result. What is the problem or what am I doing incorrectly? And one more question. When working in ALG mode with symbolic expressions, is it there any way to get them simplified upon every press of ENTER like TI-89 does? For example I enter: X+5 then ANS(1)^2-1 and I get (X+5)^2-1 If I want to simplify it, I have to select it with arrows and press ENTER again. How can I get it simplified when I enter ANS(1)^2-1 without pressing ENTER once more?
From: Virgil on 31 Jan 2010 19:11 In article <b5482632-b245-4279-a78d-4a8a140f58f8(a)m16g2000yqc.googlegroups.com>, Dima <iosaaris(a)gmail.com> wrote: > I defined a function for calculating probabilities of Poisson > distribution. When I try to calculate probability for large numbers > using floating point format I get incorrect results. The file with > screenshots is here: http://pics.livejournal.com/iosaaris/pic/0004w4hk.jpg > > The upper left screen shows how the function Poi() was defined. One > below shows the calculation of Poi(300, 200). At first it is > calculated symbolically and then the result is converted to floating > point number. In this case the result is correct. My TI-89 gives the > same result (two screenshots at right). > > When I try to calculate the same function using floating point numbers > as input (lower left screen) I get significantly different result. > > What is the problem or what am I doing incorrectly? > > And one more question. When working in ALG mode with symbolic > expressions, is it there any way to get them simplified upon every > press of ENTER like TI-89 does? For example I enter: > X+5 > then > ANS(1)^2-1 > and I get > (X+5)^2-1 > If I want to simplify it, I have to select it with arrows and press > ENTER again. How can I get it simplified when I enter ANS(1)^2-1 > without pressing ENTER once more? In the RPN mode, all you have to do is press the EVAL key. You might try that in ALG mode and see what happens.
From: Dave Hayden on 1 Feb 2010 10:56 On Jan 31, 4:54 pm, Dima <iosaa...(a)gmail.com> wrote: > I defined a function for calculating probabilities of Poisson > distribution. When I try to calculate probability for large numbers > using floating point format I get incorrect results. The file with > screenshots is here:http://pics.livejournal.com/iosaaris/pic/0004w4hk.jpg > > The upper left screen shows how the function Poi() was defined. One > below shows the calculation of Poi(300, 200). At first it is > calculated symbolically and then the result is converted to floating > point number. In this case the result is correct. My TI-89 gives the > same result (two screenshots at right). > > When I try to calculate the same function using floating point numbers > as input (lower left screen) I get significantly different result. > > What is the problem or what am I doing incorrectly? Floating point numbers on the HP can't go higher than 10^499. In addition, they are limited to 12 significant digits. You're computing Poi(y,k) = e^(-y)*y^k/k!. So Poi(300,200) = e^-300 * 300^200/200!. 300^200 and 200! are far beyond the limits floating point numbers. This is a very old problem with computers. The trick is to change the order of evaluation. Instead of evaluating 300^200 and dividing by 200!, you need to evaluate (300/200)*(300/199)*(300/198)*...(300/2)* (300/1). Sorry, I don't have the time right now to figure out exactly how to do this. It's too bad that HP doesn't supply a LNFACT() function where LNFACT (x) = ln(x!). This is pretty easy to compute from ln(gamma(x)) which can be computed directly. If you had LNFACT() then ln(POI(y,k)) = -y +k*ln(y)-LNFACT(k), which are all reasonably sized numbers that can be represented in the calculator. So POI(y,k) = e^(-y+k*ln(y)-LNFACT(k)) Dave
From: mjc on 1 Feb 2010 16:10 On Feb 1, 7:56 am, Dave Hayden <d...(a)larou.com> wrote: > On Jan 31, 4:54 pm, Dima <iosaa...(a)gmail.com> wrote: > > > I defined a function for calculating probabilities of Poisson > > distribution. When I try to calculate probability for large numbers > > using floating point format I get incorrect results. The file with > > screenshots is here:http://pics.livejournal.com/iosaaris/pic/0004w4hk.jpg > > > The upper left screen shows how the function Poi() was defined. One > > below shows the calculation of Poi(300, 200). At first it is > > calculated symbolically and then the result is converted to floating > > point number. In this case the result is correct. My TI-89 gives the > > same result (two screenshots at right). > > > When I try to calculate the same function using floating point numbers > > as input (lower left screen) I get significantly different result. > > > What is the problem or what am I doing incorrectly? > > Floating point numbers on the HP can't go higher than 10^499. In > addition, they are limited to 12 significant digits. You're computing > Poi(y,k) = e^(-y)*y^k/k!. So Poi(300,200) = e^-300 * 300^200/200!. > 300^200 and 200! are far beyond the limits floating point numbers. > > This is a very old problem with computers. The trick is to change the > order of evaluation. Instead of evaluating 300^200 and dividing by > 200!, you need to evaluate (300/200)*(300/199)*(300/198)*...(300/2)* > (300/1). Sorry, I don't have the time right now to figure out exactly > how to do this. > > It's too bad that HP doesn't supply a LNFACT() function where LNFACT > (x) = ln(x!). This is pretty easy to compute from ln(gamma(x)) which > can be computed directly. If you had LNFACT() then ln(POI(y,k)) = -y > +k*ln(y)-LNFACT(k), which are all reasonably sized numbers that can be > represented in the calculator. So POI(y,k) = e^(-y+k*ln(y)-LNFACT(k)) > > Dave I have been saying for YEARS that the HP calculators need a lngamma function. An easy way to do it yourself in user RPL would be to use ln(gamma(x)) for 0 < x < 100 or so, and use Stirlings apporximation for larger x. You can use Lanczos' approximation for all complex values with positive imaginary part, but it is more complicated. Martin Cohen
From: datajerk on 3 Feb 2010 15:17
On Feb 1, 2:10 pm, mjc <mjco...(a)acm.org> wrote: > On Feb 1, 7:56 am, Dave Hayden <d...(a)larou.com> wrote: > > > > > On Jan 31, 4:54 pm, Dima <iosaa...(a)gmail.com> wrote: > > > > I defined a function for calculating probabilities of Poisson > > > distribution. When I try to calculate probability for large numbers > > > using floating point format I get incorrect results. The file with > > > screenshots is here:http://pics.livejournal.com/iosaaris/pic/0004w4hk..jpg > > > > The upper left screen shows how the function Poi() was defined. One > > > below shows the calculation of Poi(300, 200). At first it is > > > calculated symbolically and then the result is converted to floating > > > point number. In this case the result is correct. My TI-89 gives the > > > same result (two screenshots at right). > > > > When I try to calculate the same function using floating point numbers > > > as input (lower left screen) I get significantly different result. > > > > What is the problem or what am I doing incorrectly? > > > Floating point numbers on the HP can't go higher than 10^499. In > > addition, they are limited to 12 significant digits. You're computing > > Poi(y,k) = e^(-y)*y^k/k!. So Poi(300,200) = e^-300 * 300^200/200!. > > 300^200 and 200! are far beyond the limits floating point numbers. > > > This is a very old problem with computers. The trick is to change the > > order of evaluation. Instead of evaluating 300^200 and dividing by > > 200!, you need to evaluate (300/200)*(300/199)*(300/198)*...(300/2)* > > (300/1). Sorry, I don't have the time right now to figure out exactly > > how to do this. > > > It's too bad that HP doesn't supply a LNFACT() function where LNFACT > > (x) = ln(x!). This is pretty easy to compute from ln(gamma(x)) which > > can be computed directly. If you had LNFACT() then ln(POI(y,k)) = -y > > +k*ln(y)-LNFACT(k), which are all reasonably sized numbers that can be > > represented in the calculator. So POI(y,k) = e^(-y+k*ln(y)-LNFACT(k)) > > > Dave > > I have been saying for YEARS that the HP calculators need a lngamma > function. > > An easy way to do it yourself in user RPL would be to use ln(gamma(x)) > for 0 < x < 100 or so, > and use Stirlings apporximation for larger x. > > You can use Lanczos' approximation for all complex values with > positive imaginary part, > but it is more complicated. > > Martin Cohen Visit http://www.hpmuseum.org/cgi-sys/cgiwrap/hpmuseum/archv018.cgi?read=132639, then scroll down to message #6. I posted a LogGamma and LambertW for the 50g. They are written in C with a library front end. The memory used in the 50g is on the order of bytes. The C programs will need to be installed on the SD card. Complex values supported. |