Definite integral using cumtrapz()

4 visualizaciones (últimos 30 días)
k.merchant
k.merchant el 30 de Oct. de 2017
Comentada: Star Strider el 30 de Oct. de 2017
I have a matrix of data points "Y" and want to numerically integrate each ith row of matrix Y from 0 to the ith element of vector "lim" which contains the upper limits of the integral. For example,
Y = 1 2 4 6
2 4 5 7
4 5 6 8
lim = [3 2 1]
The cumtrapz function uses unit spacing so I think the columns of Y represent the x-axis from x=0 to x=4. I would like to integrate the first row of Y from x=0 to x=3, the 2nd row from x=0 to x=2 and the 3rd row from x=0 to x=1. Is this possible to do using cumtrapz()? I'm not sure how to specify the limits.

Respuesta aceptada

Star Strider
Star Strider el 30 de Oct. de 2017
I’m not certain what result you want.
Here are two possibilities, the first using trapz, the second using cumtrapz:
Y = [1 2 4 6
2 4 5 7
4 5 6 8];
lim = [3 2 1];
for k1 = 1:numel(lim)
Yint(k1,:) = trapz(Y(k1,1:lim(k1)+1));
end
for k1 = 1:numel(lim)
Yintc{k1,:} = cumtrapz(Y(k1,1:lim(k1)+1));
end
A loop for each seems to be the only option.
  2 comentarios
k.merchant
k.merchant el 30 de Oct. de 2017
The first option works perfectly, I knew I would have to use some sort of loop, but didn't know where to start. Thank you very much for all your help today :) I had been struggling to figure this out for some time now so I really appreciate it!
Star Strider
Star Strider el 30 de Oct. de 2017
As always, my pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

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