Forum archive 2000-2006

Jun Wang - Strange numerical error

Jun Wang - Strange numerical error

by Arnold Pizer -
Number of replies: 0
inactiveTopicStrange numerical error topic started 9/30/2002; 7:12:03 AM
last post 9/30/2002; 9:40:01 AM
userJun Wang - Strange numerical error  blueArrow
9/30/2002; 7:12:03 AM (reads: 690, responses: 2)
I wrote a combinatorial problem like:

"At a bookstore, an ASU student wants to buy 2 mathematics books from 10 math books on differnet subjects. She also needs to buy 3 computer books from 10 available computer books and 4 English books from 7 available ones. How many differnet choices are there? "

The answer should be C(10,2)*C(10,3)*C(7,4) and I wrote:

$ans1 = [fact($a)/(fact($a1)*fact(8))]; #$a1=$a-8

$ans2 = [fact($b)/(fact($b1)*fact(7))]; #$b1=$b-7

$ans3 = [fact($c)/(fact($c1)*fact(3))]; #$c1=$c-3

$ans = $ans1*$ans2*$ans3;

&ANS(num_cmp($ans));

When I used $ans1, it gave me 45 as correct answer. When I used ans2, it gave me 120, when used ans3, it gave 35, all correct. However, when I used ans=ans1*ans2*ans3, it gave a number like 3.0703692407745e+24. I tried $ans=$ans1+$ans2, or $ans1*$ans2, it also gave me similiar funny numbers. However, when used $ans=45*120, no problem. Could anybody tell what could be the problem?

Jun

<| Post or View Comments |>


userJohn Jones - Re: Strange numerical error  blueArrow
9/30/2002; 9:19:29 AM (reads: 889, responses: 0)
Hi,

It looks like you are unintentionally using a perl construct. The square brackets in the definitions of $ans1, etc., are making them references to perl lists, so they are not ordinary numbers. Try removing the brackets (and optionally replacing them with parentheses).

John

<| Post or View Comments |>


userJun Wang - Re: Strange numerical error  blueArrow
9/30/2002; 9:40:01 AM (reads: 864, responses: 0)
Thanks, John. That fixed it.

Jun

<| Post or View Comments |>