Message Boards Message Boards

0
|
687 Views
|
3 Replies
|
5 Total Likes
View groups...
Share
Share this post:

Fixing a code that gives wrong count value

Posted 4 months ago

Hi there anyone!!

why does the code count the number one for only 29 times when it is really 39 "1." in the following code : in countGreaterThan1 line

expression= (179424673(n+9999980*2(179424407+n)))/((179424407+n) (-0.32+n+179424407(9999980*2+n)))
simplifiedExpression = Refine[expression, Assumptions -> n > 0]
simplifiedExpression = Simplify[expression, Assumptions -> n > 0]
results = Table[simplifiedExpression, {n, 1, 100}]
list=results
countGreaterThan1 = Count[list, _?(# >= 1 &)]
mm=countGreaterThan1
m=mm*0.08842297174111212397447584320875
resposta=mm-m
posição provável=((mm+resposta)/2)/2
3 Replies

I would rather work with exact rational numbers:

expression = (179424673 (n + 9999980*2 (179424407 + n)))/((179424407 +
        n)  (-0.32 + n + 179424407 (9999980*2 + n))) // Rationalize
results = Table[expression, {n, 1, 100}];
Count[results, r_ /; r >= 1]
Plot[expression, {n, 0, 100}, GridLines -> {{29}, {1}}]
POSTED BY: Gianluca Gorni

Thank you so much!!

list - 1 shows only 29 positive numbers.

I think what you responding to is that floating-point numbers are shown rounded to six digits in the front end. You're seeing many "1." that are really numbers that are greater or less than 1 by less than $10^{-6}$.

You can see all digits by executing Style[list, PrintPrecision -> 17].

POSTED BY: Michael Rogers
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract