Sage Quickstart for Numerical Analysis

This Sage worksheet was developed for the MAA PREP Workshop "Sage: Using Open-Source Mathematics Software with Undergraduates" (funding provided by NSF DUE 0817071).

Sage includes many tools for numerical analysis investigations.

RealField using arbitrary precision (implemented with MPFR).  The default real numbers (RR) is RealField(53) (i.e., 53 bits of precision).

{{{id=1| ring=RealField(3) /// }}}

To print the actual number (without rounding off the last few imprecise digits to only display correct digits), call the .str() method with the option "truncate=False".

(There is a patch on its way through the review process that makes it easy to set this option once instead of needing to provide it every time).

{{{id=3| ring('1').nextabove().str(truncate=False) /// '1.2' }}} {{{id=4| ring=RealField(20) ring('1').nextabove().str(truncate=False) /// '1.0000019' }}}

You can also specify the rounding mode.

{{{id=11| ringup=RealField(3,rnd='RNDD') ringdown=RealField(3,rnd='RNDU') /// }}} {{{id=13| ringup(1/9).str(truncate=False) /// '0.10' }}} {{{id=14| ringdown(1/9).str(truncate=False) /// '0.13' }}}

Sage also lets you compute using intervals to keep track of error bounds.  These basically use the round up and round down features shown above.

{{{id=19| ring=RealIntervalField(10) a=ring(1/9) a /// 0.112? }}}

The question mark doesn't quite mean what you think it does!

{{{id=8| 1/a /// 9.0? }}} {{{id=16| print (1/a).str(style='brackets') /// [8.9843 .. 9.0157] }}} {{{id=17| /// }}}

Scipy (included in Sage) has a lot of numerical algorithms.  See http://docs.scipy.org/doc/scipy/reference/

Mpmath is also included in Sage, and contains a huge amount of numerical stuff.  See http://mpmath.googlecode.com/svn/tags/0.14/doc/build/index.html

The Decimal python module has also been useful for textbook exercises which involved rounding in base 10.

{{{id=5| /// }}}