That is, if we wish to compute
While this series is the sum of an infinitely long sequence, it actually is
a number, and it often suffices to add just a few of the first few terms to
have an idea what the number is.
The key to computing a Taylor series is to formulate each term in the
underlying sequence as a function of <#65883#><#31356#>x<#31356#><#65883#> and its position
<#65884#><#31357#>i<#31357#><#65884#>. In our running example, the Taylor sequence for the exponential
function, has the shape
Assuming a fixed <#65885#><#31360#>x<#31360#><#65885#>, here is an equivalent Scheme definition:
This Taylor series has a value for all <#65907#><#31516#>x<#31516#><#65907#> that are greater than
<#65908#><#31517#>0<#31517#><#65908#>.
DrScheme also provides <#65909#><#31518#>log<#31518#><#65909#>, a primitive for computing the natural
logarithm. Compare the results for <#65910#><#31519#>ln<#31519#><#65910#> and <#65911#><#31520#>log<#31520#><#65911#>. Then use
<#72245#><#71429#><#65912#><#31521#>exact<#31521#><#65912#><#65913#><#31522#><#31522#><#31523#>-;SPMgt;<#31523#><#31524#><#31524#><#65913#><#65914#><#31525#>inexact<#31525#><#65914#><#71429#><#72245#> (see exercise~#exetaylor#31526>
It is defined for all <#65918#><#31545#>x<#31545#><#65918#>.
<#31546#>Hint:<#31546#> \ The sign of a term is positive if the index is even and negative
otherwise. Programmers use <#65919#><#31547#>cond<#31547#><#65919#> to write this down; mathematicians
use the following trick:
Define the function <#65921#><#31557#>greg<#31557#><#65921#>, which maps a natural number to the
corresponding term in this sequence. Then use <#65922#><#31558#>series<#31558#><#65922#> to determine
approximations of the value of <#31559#>Note on <#71426#>;; <#65886#><#31365#>e-taylor<#31365#> <#31366#>:<#31366#> <#31367#>N<#31367#> <#31368#><#31368#><#31369#>-;SPMgt;<#31369#><#31370#><#31370#> <#31371#>number<#31371#><#65886#><#71426#>
<#31372#>(d<#31372#><#31373#>efine<#31373#> <#31374#>(e-taylor<#31374#> <#31375#>i)<#31375#>
<#31376#>(/<#31376#> <#31377#>(expt<#31377#> <#31378#>x<#31378#> <#31379#>i)<#31379#> <#31380#>(!<#31380#> <#31381#>i)))<#31381#>
<#71427#>;; <#65887#><#31382#>!<#31382#> <#31383#>:<#31383#> <#31384#>N<#31384#> <#31385#><#31385#><#31386#>-;SPMgt;<#31386#><#31387#><#31387#> <#31388#>number<#31388#><#65887#><#71427#>
<#31389#>(d<#31389#><#31390#>efine<#31390#> <#31391#>(!<#31391#> <#31392#>n)<#31392#>
<#31393#>(c<#31393#><#31394#>ond<#31394#>
<#31395#>[<#31395#><#31396#>(=<#31396#> <#31397#>n<#31397#> <#31398#>0)<#31398#> <#31399#>1]<#31399#>
<#31400#>[<#31400#><#31401#>else<#31401#> <#31402#>(*<#31402#> <#31403#>n<#31403#> <#31404#>(!<#31404#> <#31405#>(sub1<#31405#> <#31406#>n)))]<#31406#><#31407#>))<#31407#>
The first function computes the term; the second computes the factorial of
a natural number. To compute the value of <#31422#>(d<#31422#><#31423#>efine<#31423#> <#31424#>(e-power<#31424#> <#31425#>x)<#31425#>
<#31426#>(l<#31426#><#31427#>ocal<#31427#> <#31428#>(<#31428#><#31429#>(d<#31429#><#31430#>efine<#31430#> <#31431#>(e-taylor<#31431#> <#31432#>i)<#31432#>
<#31433#>(/<#31433#> <#31434#>(expt<#31434#> <#31435#>x<#31435#> <#31436#>i)<#31436#> <#31437#>(!<#31437#> <#31438#>i)))<#31438#>
<#31439#>(d<#31439#><#31440#>efine<#31440#> <#31441#>(!<#31441#> <#31442#>n)<#31442#>
<#31443#>(c<#31443#><#31444#>ond<#31444#>
<#31445#>[<#31445#><#31446#>(=<#31446#> <#31447#>n<#31447#> <#31448#>0)<#31448#> <#31449#>1]<#31449#>
<#31450#>[<#31450#><#31451#>else<#31451#> <#31452#>(*<#31452#> <#31453#>n<#31453#> <#31454#>(!<#31454#> <#31455#>(sub1<#31455#> <#31456#>n)))]<#31456#><#31457#>)))<#31457#>
<#31458#>(series<#31458#> <#31459#>10<#31459#> <#31460#>e-taylor)))<#31460#>
<#31466#>Exercise 23.3.6<#31466#>
<#72344#>;; <#72244#><#71428#><#65899#><#31480#>exact<#31480#><#65899#><#65900#><#31481#><#31481#><#31482#>-;SPMgt;<#31482#><#31483#><#31483#><#65900#><#65901#><#31484#>inexact<#31484#><#65901#><#71428#> <#31485#>:<#31485#> <#31486#>number<#31486#> <#31487#>[<#31487#><#31488#>exact]<#31488#> <#31489#><#31489#><#31490#>-;SPMgt;<#31490#><#31491#><#31491#> <#31492#>number<#31492#> <#31493#>[<#31493#><#31494#>inexact]<#31494#> <#72244#><#72344#>
Test the function and add it to <#65902#><#31498#>e-power<#31498#><#65902#>'s body. Then compare the
results of <#65903#><#31499#>exp<#31499#><#65903#> and <#65904#><#31500#>e-power<#31500#><#65904#>. Increase the number of items
in the series until the difference between the results is
small.~ Solution<#65905#><#65905#>
<#31506#>Exercise 23.3.7<#31506#>