Definite integral using cumtrapz()

4 vues (au cours des 30 derniers jours)
k.merchant
k.merchant le 30 Oct 2017
Commenté : Star Strider le 30 Oct 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.

Réponse acceptée

Star Strider
Star Strider le 30 Oct 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 commentaires
k.merchant
k.merchant le 30 Oct 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 le 30 Oct 2017
As always, my pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Numerical Integration and Differentiation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by