Pre-Calc Exam Notes 138

Pre-Calc Exam Notes 138 - 138 Chapter 6 Additional Topics...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
138 Chapter 6 Additional Topics §6.2 programming language 3 (chosen here for simplicity) the decimal module can be used to set any level of precision. 4 Below we show how to get accuracy up to 50 decimal places using Heron’s formula for the triangle in Example 2.16 from Section 2.4, by using the python interactive command shell: [1]: from decimal import * [2]: getcontext().prec = 50 [3]: a = Decimal("1000000") [4]: b = Decimal("999999.9999979") [5]: c = Decimal("0.0000029") [6]: s = (a+b+c)/2 [7]: K = s * (s-a) * (s-b) * (s-c) [8]: print Decimal(K).sqrt() 0.99999999999894999999999894874999999889618749999829 (Note: The bracketed line numbers are just command prompts, not part of the code.) Notice in this case that we do get the correct answer; the high level of precision eliminates the rounding errors shown by many calculators when using Heron’s formula. Another software option is Sage 5 , a powerful and free open-source mathematics package based on Python. It can be run on your own computer, but it can also be run through a web
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/21/2012 for the course MAC 1130 taught by Professor Dr.cheun during the Fall '11 term at FSU.

Ask a homework question - tutors are online