2012-02-11 147 views
1

我在兩組數據上使用了trapz函數,並且出現了錯誤。trapz函數給出了奇怪的結果

下面是數據的視圖: pressure drag coefficient and lift coefficient http://s17.postimage.org/inxk1xolr/cptheta.jpg

所以你能理解我的問題; y軸爲壓力系數Cp,x軸爲角度(共49個值,0:7.5:360),綠色方陣的數據爲實驗得到的數據,紅色曲線基本上爲Cp sin ),而粉紅色的是Cp cos(角度)

對紅色的trapz使用完美,它給出7.5,如果我將trapz的輸入參數反轉,我會得到這個數字的負值!問題在於粉紅色圖表,使用trapz給出了一個巨大的數字(這是錯誤的,我不應該得到這個),當切換輸入參數時,我得到另一個巨大的數字,而不是第一個數字的負數,這很奇怪,我不知道什麼是錯的,所以我用四(需要一個函數)來測試trapz

for i = 1:48 
    y = @(x) (Cp(i+1) - Cp(i))/(theta_rad(i+1) - theta_rad(i)) * x .* sin(x); 
    clll(i) = -0.5* quad(y,theta_rad(i), theta_rad(i+1)); 

end 
clll = sum(clll); 

for j = 1:48 
    f = @(t) (Cp(j+1) - Cp(j))/(theta_rad(j+1) - theta_rad(j)) * t .* cos(t); 
    cdddp(i) = 0.5* quad(f,theta_rad(j), theta_rad(j+1)); 

end 

cdddp = sum(cdddp); 

的結果對於第一循環(紅色曲線的四)我有非常密切的回答,錯誤可能是由於我在點之間使用了線性插值,而對於第二個循環,我得到了一個合理的答案,這是一個非常小的數字,它在我正在尋找的答案的範圍內。我也在Excel中嘗試了梯形法則,並且我再次得到了這個龐大的數字,所以這是我做錯了事情。


編輯:

我剛剛發現了一個錯誤,我用的是使用角度以度而非弧度的梯形!現在我得到的數字要小得多,但我認爲還有一個錯誤,因爲使用quad的整數給出了一個更明智的答案。

下面是我使用trapz

Cdp = 0.5*trapz(theta*pi/180, Cp.*cosd(theta)); %pressure drag coefficient 

Cl = -0.5*trapz(theta*pi/180, Cp.*sind(theta)); %lift coefficient 

回答

0

我現在使用的代碼,在trapz功能我得到了正確的答案使用弧度後。我試圖做的插值是廢話!我設法使用曲線擬合工具來創建一個合適的,這是非常有效的

Cdp = 0.5*trapz(theta*pi/180, Cp.*cosd(theta)); %pressure drag coefficient 

可以通過使用工具來實現:

fit1 = createFit(theta*pi/180, Cp.*cosd(theta)); 
##createFit is generated by MatLab and I only need parts of it, all the plots commands were removed. 
Cdp = 0.5*integrate(fit1,0,2*pi) ##"integrate" < this is why the tool is great, No need to export the coefficients to the workspace, create a function handle then use quad