iT邦幫忙

0

matlab的計算迴路?

  • 分享至 

  • xImage

in matlab:cos(14)=0.1367、cos(14.1)=0.0372、
計算機:cos(14)=0.9702、cos(14.1)=0.9698
請問matlab的答案為什麼和計算機不一樣?

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

2 個回答

2
一級屠豬士
iT邦大師 1 級 ‧ 2023-09-24 15:50:57
最佳解答
>>> import math
>>> 
>>> math.cos(14)
0.1367372182078336
>>> math.cos(14.1)
0.0371583847908264
>>> math.radians(14)
0.24434609527920614
>>> math.radians(14.1)
0.24609142453120045
>>> math.cos(math.radians(14))
0.9702957262759965
>>> math.cos(math.radians(14.1))
0.9698720152847468

用Python舉例

https://ithelp.ithome.com.tw/upload/images/20230924/20050647IrdNIpBv5r.png

使用的是 弧度
https://zh.wikipedia.org/zh-tw/%E5%BC%A7%E5%BA%A6

你計算機使用的是角度
上面已經有轉換的方式了.

謝謝大神!

1
whoami
iT邦新手 3 級 ‧ 2023-09-24 15:36:45

在MATLAB和大多數電腦程式語言中,三角函數(如cosine)的參數通常以弧度(radians)為單位給出,而不是角度(degrees)。

在 Python

# output the value of cos(14)
import math
print(math.cos(14))

輸出值

0.1367372182078336

謝謝仁兄!

我要發表回答

立即登入回答