和角公式

來源:互聯網
上載者:User

今天做 SICP 練習 1.15,需要用到和角公式,雖然會寫,但是忘了怎麼證明了,在 mathworld 裡找到了很精彩的證明:


這裡用到了歐拉公式,之前發過日誌記錄了證明了,不過發現用積分來證十分巧妙!


; SICP ex1.15

; 在弧度 x 很小時,其正弦值 sinx 可以用 x 代替。

; 並且有恒等式 sinx = 3sin(x/3) - 4sin3(x/3)

; 使用 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)))))

; 和標準函數比較

>(sine 0.5)

0.4794283252628956

> (sin 0.5)
0.479425538604203

=====================C 程式========================

#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;
}

====================================================

演算法時間複雜度為 log3(x / eps)。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.