Numerical double Integral on triangular domain

조회 수: 7 (최근 30일)
Marko Pesut
Marko Pesut 2020년 11월 4일
댓글: darova 2021년 3월 26일
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))

답변 (1개)

vincenzo scarnera
vincenzo scarnera 2021년 3월 26일
I want to do it on a spherical domain

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by