19.10 Power Series

I l @ ve RuBoard

Many trigonometry functions are computed using a power series . For example, the series for sine is:

sin( x ) = x - x 3 / 3! + x 5 / 5! - x 7 / 7! + ...

The question is, how many terms do we need to get four-digit accuracy? Table 19-2 contains the terms for sin( figs/u03c0.gif /2).

Table 19-2. Terms for sin( figs/u03c0.gif /2)
 

Term

Value

Total

1

x

1.571E+0

 

2

x 3 / 3!

6.462E-1

9.248E-1

3

x 5 / 5!

7.974E-2

1.005E+0

4

x 7 / 7!

4.686E-3

9.998E-1

5

x 9 / 9!

1.606E -- 4

1.000E+0

6

x 11 / 11!

3.604E-6

1.000E+0

From this we conclude that five terms are needed. However, if we try to compute sin( figs/u03c0.gif ), we get Table 19-3.

Table 19-3. Terms for sin(p)
 

Term

Value

Total

1

x

3.142E+0

 

2

x 3 / 3!

5.170E+0

-2.028E+0

3

x 5 / 5!

2.552E-0

5.241E-1

4

x 7 / 7!

5.998E-1

-7.570E-2

5

x 9 / 9!

8.224E-2

6.542E-3

6

x 11 / 11!

7.381E-3

-8.388E-4

7

x 13 / 13!

4.671E-4

-3.717E-4

8

x 15 / 15!

2.196E-5

-3.937E-4

9

x 17 / 17!

7.970E-7

-3.929E-4

10

x 19 / 19!

2.300E-8

-3.929E-4

figs/u03c0.gif needs nine terms; so different angles require a different number of terms. (A program for computing the sine to four-digit accuracy showing intermediate terms is included in Appendix D.)

Compiler designers have a dilemma when it comes to designing a sine function. If they know ahead of time the number of terms to use, they can optimize their algorithms for that number of terms. However, they lose accuracy for some angles. So a compromise must be struck between speed and accuracy.

Don't assume that because the number came from the computer, it is accurate. The library functions can generate bad answers especially when working with excessively large or small values. Most of the time you will not have any problems with these functions, but you should be aware of their limitations.

Finally, there is the question of what is sin(1,000,000)? Our floating-point format is good for only four digits. The sine function is cyclical. That is, sin(0) = sin(2 figs/u03c0.gif ) = sin(4 figs/u03c0.gif ). Therefore, sin(1,000,000) is the same as sin(1,000,000 mod 2 figs/u03c0.gif ).

Because our floating-point format is good to only four digits, sin(1,000,000) is actually sin(1,000, xxx ), where xxx represents unknown digits. But the sin function is periodic with a period 2 figs/u03c0.gif , which means it goes through its full range in a space of 2 figs/u03c0.gif . Because the range of unknown (1,000) is bigger than 2 figs/u03c0.gif , the error renders meaningless the result of the sine.

Insignificant Figures

I attended a physics class at Cal Tech taught by two professors. One was giving a lecture on the sun when he said, "... and the mean temperature of the inside of the sun is 13,000,000 to 25,000,000 degrees." At this point the other instructor broke in and asked, "Is that Celsius or Kelvin?" (absolute zero on the Kelvin scale = degrees Celsius -273)

The first lecturer turned to the board for a minute and then said, "What's the difference?" The moral of the story is that when your calculations have a possible error of 12,000,000, a difference of 273 doesn't mean very much.

I l @ ve RuBoard


Practical C++ Programming
Practical C Programming, 3rd Edition
ISBN: 1565923065
EAN: 2147483647
Year: 2003
Pages: 364

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net