Taylor Series

[Home]   [Puzzles & Projects]    [Delphi Techniques]   [Math topics]   [Library]   [Utilities]

 

 

Search

Search WWW

Search DelphiForFun.org

As of October, 2016, Embarcadero is offering a free release of Delphi (Delphi 10.1 Berlin Starter Edition ).     There are a few restrictions, but it is a welcome step toward making more programmers aware of the joys of Delphi.  They do say "Offer may be withdrawn at any time", so don't delay if you want to check it out.  Please use the feedback link to let me know if the link stops working.

 

Support DFF - Shop

 If you shop at Amazon anyway,  consider using this link. 

     

We receive a few cents from each purchase.  Thanks

 


Support DFF - Donate

 If you benefit from the website,  in terms of knowledge, entertainment value, or something otherwise useful, consider making a donation via PayPal  to help defray the costs.  (No PayPal account necessary to donate via credit card.)  Transaction is secure.

Mensa® Daily Puzzlers

For over 15 years Mensa Page-A-Day calendars have provided several puzzles a year for my programming pleasure.  Coding "solvers" is most fun, but many programs also allow user solving, convenient for "fill in the blanks" type.  Below are Amazon  links to the two most recent years.

Mensa® 365 Puzzlers  Calendar 2017

Mensa® 365 Puzzlers Calendar 2018

(Hint: If you can wait, current year calendars are usually on sale in January.)

Contact

Feedback:  Send an e-mail with your comments about this program (or anything else).

Search DelphiForFun.org only

 

 

 

 

Problem Description

A Taylor series is a technique for estimating many important functions to any desired degree of accuracy.    Here's a demo program that  calculates ex  and sine(x) as Taylor series expansions up to 19 significant digits.   

Background & Techniques

We recently published a Big Float program which investigates techniques for performing basic arithmetic on decimal numbers of arbitrary size.   This raised the question of how to emulate the trigonometric,  log,  and exponential functions available in the Windows calculator program.  The Taylor/Maclaurin power series provide one answer - such series  are probably close to the procedures used by most hardware and software scientific calculators.    

Power series are a topic in all 1st year Calculus courses; I won't  try to explain here how or why they work.   Let's just say that they are polynomials of infinite length which converge to the true value of the functions which they approximate.   They exist for all functions with  nice smooth graphs without any breaks or square corners  (or "continuously differentiable" as a mathematician would say).    Google returns 1.9 million hits for "Taylor series" so there is no shortage of material for additional reading.   For our purposes, we'll be satisfied to successfully evaluate a few examples just to see that they do indeed  work!

The "Taylor" who loaned his name to the series referenced  here is Brook Taylor, an English mathematician who developed the technique in the early 1700's and whose handsome  picture appears at the top of this page.   

The exponential function, excan be expanded as 1 + x2/2! + x3/3! + x4/4! + x5/5! .....  and the sine function  as x - x3/3! + x5/5! - x7/7! + x9/9! ........    I did not include the Big Float unit into this program so for now, we'll be satisfied to evaluate the target  functions up the limit of accuracy of Intel's internal extended data type  (19 significant digits).

The program calculates the functions step-by-step, comparing the returned value to Delphi's math library value at each  step.   

Note for programmers:  While extended data types should be accurate to at least 19 digits, Delphi's Format statement does not seem to want to present more that 18 digits of precision.  A format string  of '%20.18f' displays fine; '%21.19f' displays only two digits to the right  of the decimal point!   If any knows of any documentation about this, please let me know.

Running/Exploring the Program 

bulletDownload source
bulletDownload  executable

Suggestions for Further Explorations

Implement additional functions.
Incorporate  the Big Float unit to increase accuracy of results.    (Although 19 significant digits is probably sufficient for all practical purposes.)
Limitations of Delphi Format statement  described above.

 

Original Date: March 19, 2003 

Modified: May 15, 2018

 
  [Feedback]   [Newsletters (subscribe/view)] [About me]
Copyright © 2000-2018, Gary Darby    All rights reserved.