各位大大門好
非常感謝上一篇在推文回答我的問題
經過嘗試之後
發現經由trapz之後的值都會比較小,照下組數據應該算出來結果是要大於180
X軸data是:
x = 0 : 6 : 180;
Y軸data是:
y = [0, 1.55464981024354e-06, 5.83937700379266e-06, 1.23059070365907e-05,
2.04318517979475e-05, 2.97201993727277e-05, 3.97004137484849e-05,
4.99306499001924e-05, 6.00008482354052e-05, 6.95364018836329e-05,
7.82020677438476e-05, 8.57059548886770e-05, 9.18033097894118e-05,
9.62998878420099e-05, 9.90548056864478e-05, 9.99826536894291e-05,
9.90548056867048e-05, 9.62998878424930e-05, 9.18033097900734e-05,
8.57059548894716e-05, 7.82020677447207e-05, 6.95364018845333e-05,
6.00008482362841e-05, 4.99306499010090e-05, 3.97004137491947e-05,
2.97201993732905e-05, 2.04318517983462e-05, 1.23059070368372e-05,
5.83937700390511e-06, 1.55464981026809e-06, 0];
方法一: 基本土法煉鋼
area = zeros(1,31)
for i = 1:30
area(1,i) = sqrt((y(i+1) - y(i))^2 + (x(i+1) - x(i))^2);
area(1,31) = area(1,31) + area(1,j);
end
算出曲線總長度答案是 area(1,31) = 1.800000000001348e+02;
方法二: 用interpl內插再使用trapz積分
曲線在上的弧長s=∫√(1+y'2 )dx
x = 0 : 6 : 180;
xi = 0 : 0.00001 : 180;
yi = interpl(x, y, xi, 'spline');
plot(x, y, 'o', xi, yi);
dy = diff(yi);
area1 = 0.00001*trapz((1+dy.^2).^0.5);
算出曲線總長度答案是 area1 = 1.7999999e+02;
不清楚哪邊出了問題
希望有大大能解惑
謝謝