Finite Integral with periodic values of x

3 ビュー (過去 30 日間)
Manish Kumar
Manish Kumar 2019 年 3 月 12 日
コメント済み: Torsten 2019 年 3 月 12 日
Dear All,
Range of my x axis is 0.3 to 4.5. I want to integrate my x and y data with x range from 0.3 to 4.5 with the interval of 0.01. First column of the excel sheet is x and 2nd column is y. I write a code as below:
for i = 0.3:4.5:0.01
idx = (x>=i & x<=4.5);
xp = x(idx);
yp = y(idx);
f(i,:)=trapz(xp,yp)
end
I need improvement on this script. Please help.

採用された回答

Torsten
Torsten 2019 年 3 月 12 日
編集済み: Torsten 2019 年 3 月 12 日
idx = (x>=0.3 & x<=4.5);
xp = x(idx);
yp = y(idx);
F = cumtrapz(xp,yp);
F = F(end) - F;
plot(xp,F)
  2 件のコメント
Manish Kumar
Manish Kumar 2019 年 3 月 12 日
編集済み: Manish Kumar 2019 年 3 月 12 日
i want to calculate the integral by varying the limit. Lower limit is 0.3, 0.31,0.32,0.33....4.5 and upper limit is 4.5
Torsten
Torsten 2019 年 3 月 12 日
If you insist varying the lower limit by a fixed amount, you can use
index = 0;
for iter = 0.3:0.01:4.5
index = index + 1;
idx = (x>=iter & x<=4.5);
xp = x(idx);
yp = y(idx);
xiter(index) = iter;
Fiter(index) = trapz(xp,yp);
end
plot(xiter,Fiter)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by