How to calculate a double integral inside the domain of intersection of two functions?

조회 수: 5 (최근 30일)
Mehdi 2023년 1월 16일
편집: Torsten 2023년 1월 25일
I want to calculate a double integral of an arbitrary function (f) inside the region of intersection of two other functions. Please suggest a fast and convenient approach.
clear
JJ = 5;
II = 5;
W = rand(II, JJ);
syms x y
w = sym('0');
f = sym('0');
for i=1:II
for j=1:JJ
w =w+W(i, j)*legendreP(i-1, x)*legendreP(j-1, y);
f =f+(legendreP(i-1, x)*legendreP(j-1, y))^2;
end
end
H = 0.5*(1+tanh(w));
fsurf(w,[-1,1,-1,1],'red')
hold on
% figure
fsurf(H,[-1,1,-1,1],'blue')
%F = double integral of f inside the domain of intersection of two functions as
%the region showed in pic
댓글 수: 13이전 댓글 11개 표시이전 댓글 11개 숨기기
Mehdi 2023년 1월 18일
Any suggestion to speed up the calculation?
clc
clear
JJ = 9;
II = 9;
W = 01*rand(II, JJ);
syms x y
w = sym('0');
f = sym('0');
for i=1:II
for j=1:JJ
w =w+W(i, j)*legendreP(i-1, x)*legendreP(j-1, y);
f =f+(legendreP(i-1, x)*legendreP(j-1, y))^2;
end
end
H = 0.5*(1+tanh(11*w));
f = matlabFunction(f,'Vars',[x y]);
g = matlabFunction(H-0.5,'Vars',[x y]);
D = @(x,y)f(x,y).*(g(x,y)>0);
Dint = integral2(D,-1,1,-1,1)
Torsten 2023년 1월 18일
편집: Torsten 2023년 1월 18일
Any suggestion to speed up the calculation?
No. I remember we had this integration problem before. And the region where g(x,y)>0 is quite complicated.

댓글을 달려면 로그인하십시오.

답변 (1개)

Bjorn Gustavsson 2023년 1월 17일
편집: Bjorn Gustavsson 2023년 1월 17일
Perhaps you can use Green's theorem (you'd be very lucky if you could - but if you were to be that lucky in this case it would be a shame to miss it). That would take you from a sum of integrals over rather complicated regions to perhaps simpler integrals around the boundaries of the region. That would be nice. Given the shape of your function it doesn't seem entirely improbable.
For the case where you actually have to perform the calculations you would use the steps suggested in @Torsten's comment.
HTH
댓글 수: 5이전 댓글 3개 표시이전 댓글 3개 숨기기
Mehdi 2023년 1월 25일
편집: Mehdi 2023년 1월 25일
C can be found by FEX submission availiable through https://www.mathworks.com/matlabcentral/fileexchange/74010-getcontourlinecoordinates?s_tid=srchtitle. The problem for me is to find M and L (a,b). Any suggestions?
Torsten 2023년 1월 25일
편집: Torsten 2023년 1월 25일
a = b = 0.
You can use any function M with dM/dx = f.
But you need a symbolic integration here.
I doubt the whole process will be faster than using integral2 directly, apart from the problems of evaluating the curve integral.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by