Definite integral using cumtrapz()
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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.
0 commentaires
Réponse acceptée
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
Plus de réponses (0)
Voir également
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!