Numerical double Integral on triangular domain
8 views (last 30 days)
Show older comments
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))
0 Comments
Answers (1)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!