Numerical double Integral on triangular domain

7 vues (au cours des 30 derniers jours)
Marko Pesut
Marko Pesut le 4 Nov 2020
Commenté : darova le 26 Mar 2021
Hi everyone,
I'm trying to compute the integral of a function f(x,y) over a triangular domain given by 4 < x <8 and 4-x < y < 0. f(x,y) is a n x n matrix where y varies over the rows and x over the lines. The code I wrote does the job :
x=linspace(4,8,n);
endpt=x-4; % Gives the lower bound for the allowed region of y
for i=1:n
y(:,i)=linspace(0,endpt(i),n); % Each row j of this matrix contains all allowed values of y for a given value of x i.e 4-x(j) < y < 0.
end
for i=n
y_int(i)=trapz(y(:,i),f(:,i)); % Each iteration integrates the rows of f from 0 to 4-x(i)
end
final_int = trapz (x,-y_int); % Integration over the domain of x (notice the - sign to account for the fact we are integrating above from 0 down to 4-x(j).)
However, I would like to know if it is possible to write the same computation using the cumtrapz function of matlab in order to avoid the second loop (the n integrations) ? I tried something like this but it doesn't work ... Thank you for your help !
t1=linspace(-4,0,n1);
res=cumtrapz(t1,f,2);
trapz(s1,-diag(res))

Réponses (1)

vincenzo scarnera
vincenzo scarnera le 26 Mar 2021
I want to do it on a spherical domain
  1 commentaire
darova
darova le 26 Mar 2021
PLease create your own question

Connectez-vous pour commenter.

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