Loop to calculate area under curve using rectangle methode

조회 수: 4 (최근 30일)
Andre
Andre 2018년 4월 18일
답변: Akira Agata 2018년 4월 23일
Hello everyone I have a graph plotted in Matlab (no function), as data was imported via Excel, I am looking for a loop to calculate the area under the curve of each interval and then add them to get the entire area
Here's how my graph look like
  댓글 수: 2
Akira Agata
Akira Agata 2018년 4월 18일
How about using trapz function, instead of trying rectangle method. Or, do you have to try rectangle method for some reason?
Andre
Andre 2018년 4월 19일
Actually, I have a research about the rectangular method, that's why

댓글을 달려면 로그인하십시오.

답변 (1개)

Akira Agata
Akira Agata 2018년 4월 23일
Sorry for my late response. Here is an simple example.
% Sample data
dx = pi/10;
x = 0:dx:2*pi;
y = 1+sin(x);
% integral of y = f(x) via trapezoidal method (S1) and rectangle method (S2)
S1 = trapz(x,y);
S2 = sum(y*dx);

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by