Loop to calculate area under curve using rectangle methode

4 visualizaciones (últimos 30 días)
Andre
Andre el 18 de Abr. de 2018
Respondida: Akira Agata el 23 de Abr. de 2018
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 comentarios
Akira Agata
Akira Agata el 18 de Abr. de 2018
How about using trapz function, instead of trying rectangle method. Or, do you have to try rectangle method for some reason?
Andre
Andre el 19 de Abr. de 2018
Actually, I have a research about the rectangular method, that's why

Iniciar sesión para comentar.

Respuestas (1)

Akira Agata
Akira Agata el 23 de Abr. de 2018
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);

Categorías

Más información sobre Numerical Integration and Differentiation en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by