Given that the absolute error after n terms is bounded by the value of the next term (i.e. How many terms of the series will be required to get an approximate value of Pi that is accurate to 20 significant decimal digits. It's "accurate." The problem is that it will take a lot of terms (a whole lot of terms) to converge to a value that has more precision than the 16 or 17 significant decimal digits that you get with double precision Java variables. The problem isn't with the "accuracy" of the infinite series you are using. (Who cares? That's why we have computers, right? Let them do the work.)Īfter ten thousand terms, the approximation is only correct to four significant decimal digits. (This is an upper bound of the error of the sum so far.) Term = numerator divided by denominator // Use BigDecimal divide() with mc context to the absolute value of the next term.ĭenominator = denominator plus 2 // Use BigDecimal add(bigTwo) convergent series, truncation error is less than or equal Sum = sum minus term // Use BigDecimal subtract() method Sum = sum plus term // Use BigDecimal add() method Term Initial value numerator divided by denominatorĭeclare and initialize the boolean variable: Declare and initialize int variables numTerms and precision.Ĭreate a MathContext object with your value of precision.ĭeclare and initialize BigDecimal objects
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |