Using trapz for non-linear data points

4 ビュー (過去 30 日間)
yashvin
yashvin 2015 年 7 月 22 日
コメント済み: Star Strider 2015 年 7 月 22 日
Hello,
I have a speed vs time plot shown below.
I want to know how acccurate is the trapz function in MATLAB for calculating the distance travelled (i.e area under the graph). Would you suggest if there is an another means of obtaining a better approximation for the area under the graph?

採用された回答

Star Strider
Star Strider 2015 年 7 月 22 日
I would use cumtrapz to give instantaneous distance traveled, for instance:
dist_nm = cumtrapz(airspeed, time_num);
I would create a time vector using datenum, subtracting the first value to create a realistic time vector in the context of your data:
time_num = datenum(time) - datenum(time(1));
Do the appropriate adjustments to the datenum calls if your ‘time’ data are not already in date number format.
  2 件のコメント
yashvin
yashvin 2015 年 7 月 22 日
Hi
Yes, I had used this approach itself:
time_chunk_slt=Time_sub_chunk{i,f}; %gets the current time chunk
time_chunk_slt_dur= time_chunk_slt-time_chunk_slt(1); % gets the value of the time duration stating from zero to the current time
time_chunk_slt_dur_sec=seconds(time_chunk_slt_dur);
time_chunk_slt_dur_sec_hr{i,f}=time_chunk_slt_dur_sec/3600;
If I want simply the distance travelled throughout the whole time duration, the trapz is also fine right?
dist_nm = trapz(airspeed, time_num);
I read that it uses trapezoidal area for each time step to calculate the distance in this case. So the last value of cumtrapz should correspond to trapz right?
Star Strider
Star Strider 2015 年 7 月 22 日
Correct. The last value of cumtrapz is the value of the entire integral, equivalent to trapz.

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

その他の回答 (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