Is there a way to vectorize trapezoidal numerical integration?

3 Ansichten (letzte 30 Tage)
Jon B.
Jon B. am 12 Apr. 2022
Kommentiert: Jon B. am 12 Apr. 2022
I was wondering whether there might be a way to (numerically) integrate several functions over different integration domains in a parallel manner. Using Matlab's trapz function, I can specify an "intergation domain"
X = [1 2.5 7 10];
and what essentially amount to the image of this vector under a set of, say, 3 different function
Y = [5.2 7.7 9.6 13.2;
4.8 7.0 10.5 14.5;
4.9 6.5 10.2 13.8];
Integration via trapz is then carried out as
trapz(X, Y, 2)
My problem is that I'd like to integrate each function over a different range. So essentially I'd like to have
X = [1 2.5 7 10;
3 4.1 8 11;
1 2.3 6 19];
Just for clarity: I can generate the desired result via a loop
for j = 1:3
out(j) = trapz(X(j,:), Y(j,:));
end
but since I am working with 1,000nds of function with 10,000nds of nodes in the integration domain this is not particularly expedient.
I'd very much appreciate it if anyone might have an idea how to go about parallelizing this task.
Many thanks.

Akzeptierte Antwort

Matt J
Matt J am 12 Apr. 2022
ab=conv2(Y,[1,1]/2,'valid');
h=diff(X,1,2);
out=sum(ab.*h,2);

Weitere Antworten (0)

Produkte


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by