Today do SICP exercise 1.15, need to use and angle formula, although will write, but forgot how to prove, in MathWorld found a very wonderful proof:
Euler's formula has been used here, and it has been documented before, but it is very ingenious to find the points to prove it.
; SICP ex1.15
; In radians X is very small, the sine of the sinx can be replaced by X.
; and has identities Sinx = 3sin (X/3)-4sin3 (X/3)
; Execute with DrScheme
;
; ;
;
; ;;; ; ; ;; ;;;
; ; ; ; ;; ; ; ;
; ; ; ; ; ; ;
; ;;; ; ; ; ;;;;;
; ; ; ; ; ;
; ; ; ; ; ; ; ;
; ;;; ; ; ; ;;;
;
;
(define (Cube x) (* x x x))
(define (P x) (-(* 3 x) (* 4 (Cube x)))
(Define (sine angle)
(if (Not (> (ABS angle) 0.01))
Angle
(P (sine (/angle 3.0))))
; Comparison with standard functions
> (sine 0.5)
0.4794283252628956
> (Sin 0.5)
0.479425538604203
=====================c program ========================
#include <stdio.h>
#include <math.h>
#define EPS 0.01
Double sine (double x)
{
if (Fabs (x) < EPS) return x;
Double sine3th = sine (x/3.0);
Return 3 * sine3th-4 * sine3th * sine3th * sine3th;
}
int main ()
{
printf ("%.6f/n", sine (0.5));
printf ("%.6f/n", sin (0.5));
return 0;
}
====================================================
The algorithm has a time complexity of LOG3 (x/eps).