11.07.2015 Views

Advanced Programming Guide

Advanced Programming Guide

Advanced Programming Guide

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

208 • Chapter 5: Numerical <strong>Programming</strong> in MapleThis is known as catastrophic cancellation. During the subtractionthe eight leading digits cancel out, leaving only two significant digits inthe result.One advantage of Maple software floats, in contrast to fixed-precisionfloating-point numbers systems, is that the user can increase the precisionto reduce roundoff errors. For example, increasing Digits to 20 dramaticallyimproves the result.> Digits := 20;Digits := 20> x + y + z;3.141592654Employ standard numerical analysis techniques to avoid large errorsaccumulating in your calculations. Often, reordering the operations leadsto a more accurate final result. For example, when computing a sum, addthe numbers with the smallest magnitudes first.5.4 Extending the evalf CommandThe evalf command can evaluate many functions and constants, suchas sin and Pi. You can also define your own functions or constants, andextend evalf by adding information about how to compute such functionsor constants.Defining New ConstantsYou can define a new constant and write procedures that manipulate thisconstant symbolically. You can then write a procedure that calculates afloating-point approximation of your constant to any number of digits. Ifyou assign the procedure a name of the form ‘evalf/constant/name‘,Maple invokes the procedure when you use evalf to evaluate an expressioncontaining your constant, name.ExampleLet the name MyConst represent the following infinite series:MyConst =∞∑ (−1) i π ii=12 i i!

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!