Why did I get different results by using degree/radiance as the unit in the integration?

2 ビュー (過去 30 日間)
today I wonder if the unit (degree/radiance) of integration variable matters in Matlab, so I tried these 2 peices of codes:
x_tst=0:0.1:180; % in degree
y_tst=sind(x_tst);
Q1=trapz(x_tst,y_tst)
Q1 =
1.145915299373423e+02
x_tst_deg=0:0.1:180;
x_tst_rad=x_tst_deg./180.*pi;% in radiance
y_tst=sin(x_tst_rad);
Q2=trapz(x_tst_rad,y_tst)
Q2 =
1.999949230172279
As you can see, the results are different, could someone tell me why we have this problem in MATLAB?
Must we use radiance as the unit of angle in Matlab (especially in the integration)?
What if I would like to adopt 'degree' as the unit of the integration variable?

採用された回答

KSSV
KSSV 2020 年 6 月 23 日
編集済み: KSSV 2020 年 6 月 23 日
Note that both the results are same...but they are in different units....
Your Q1 is in degrees and Q2 is in radians.....Convert them to the same units and see...
% Check in degrees
Q2*180/pi
Q1
% check in radians
Q1*pi/180
Q2
  4 件のコメント
Shuangfeng Jiang
Shuangfeng Jiang 2020 年 6 月 23 日
Can you please explain why Q1 deviates from the correct result(2)?
KSSV
KSSV 2020 年 6 月 23 日
Simple man...your x-values i.e x_tst are in radians for Q1 and are in degrees for Q2...as the area is length*breadth...your x-values are different in both the cases...so your values are different.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNumerical Integration and Differentiation についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by