Numerical double Integral on triangular domain

8 ビュー (過去 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
  1 件のコメント
darova
darova 2021 年 3 月 26 日
PLease create your own question

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeNumerical Integration and Differentiation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by