Definite integral using cumtrapz()
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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.
0 comentarios
Respuesta aceptada
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
Más respuestas (0)
Ver también
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!