Adding sine
No. 118
Implementing .
Q: |
We may implement in a similar fashion to Equation 1, “Power series definition of ”: Equation 2. Power series definition of
Extend Figure 297, “An implementation sketch for the exponential” by adding a
second method Test your implementation by calculating the known values
,
and
using |
||
A: |
Taking seven terms into account we have the following results: sin(pi/2)=0.9999999999939768, difference=-6.023181953196399E-12
sin(pi)=-7.727858895155385E-7, difference=-7.727858895155385E-7
sin(4 * PI)=-9143.306026012957, difference=-9143.306026012957 As with the implementation of larger (positive or negative) argument values show growing differences. On the other hand the approximation is remarkably precise for smaller arguments. The reason again is the fact that our power series is just a polynomial approximation showing errors growing along with larger argument values: Figure 299. Comparing sin(x) and its approximation.
The approximation is very good for smaller values but diverges rapidly for . You may also view the implementation of double Math.sin(double) along with its Javadoc. |