
三角函數
假如手上沒有工具,該如何計算三角函數的值呢?我們須運用近似求值的方法,即在角度值(弧度值)足夠小的情況下,該等式成立:
sinx≈x
同時,我們應用下面的公式,持續迭代減小x的值:
sinx= 3sin(x/3) 4sin3(x/3)
代碼實現如下:
function abs(x) { return x >= 0 ? x : -x;}function cube(x) { return x * x * x;}function p(x) { return 3 * x - 4 * cube(x);}function sine(angle) { return !(abs(angle) > 0.1) ? angle : p(sine(angle / 3));//p for procedure}
此處學到的是,等式兩邊取不同的argument,運行測試:
> sine(12.15)-0.39980345741334> sine(3.14/6)0.5000259145195963
這道題目啟發我,編程確實可以用在日常的思考和數學計算中。
特別聲明:以上內容(如有圖片或視頻亦包括在內)為自媒體平臺「網易號」用戶上傳並發布,本平臺僅提供信息存儲服務。
Notice: The content above (including the pictures and videos if any) is uploaded and posted by a user of NetEase Hao, which is a social media platform and only provides information storage services.