Efficient way to compute a double integral within a double integral

조회 수: 2 (최근 30일)
Igor Dakic
Igor Dakic 2019년 6월 6일
댓글: Torsten 2019년 6월 11일
Hi all,
I would like to know what is the easiest and most efficient way to solve the integration shown in the figure attached.integration.JPG
I tried the following code, but it doesn't work:
R1 = @(x1,x2) integral2(@(x3,x4) fun_g(x1,x2,x3,x4),l3,u3,l4,u4);
R = integral2(R1.*@fun_f,l1,u1,l2,u2);
function f = fun_f(x1,x2)
% here we define f function (it is a rather complex function)
end
function g = fun_g(x1,x2,x3,x4)
% here we define g function (it is a rather complex function)
end
Thanks in advance!

채택된 답변

Torsten
Torsten 2019년 6월 7일
편집: Torsten 2019년 6월 7일
function main
l1 = ...;
u1 = ...;
l2 = ...;
u2 = ...;
value_outer_integral = integral2(@fun,l1,u1,l2,u2)
end
function value_inner_integral = fun(x1,x2)
l3 = ...;
u3 = ...;
l4 = ...;
u4 = ...;
for i = 1:numel(x1)
value_inner_integral(i) = fun_f(x1(i),x2(i))*integral2(@(x3,x4)driver_fun_g(x1(i),x2(i),x3,x4),l3,u3,l4,u4);
end
end
function g = driver_fun_g(x1,x2,x3,x4)
for i = 1:numel(x3)
g(i) = fun_g(x1,x2,x3(i),x4(i));
end
end
function f = fun_f(x1,x2)
% return f(x1,x2) for scalar values of x1 and x2
end
function g = fun_g(x1,x2,x3,x4)
% return g(x1,x2,x3,x4) for scalar values of x1, x2, x3 and x4
end
  댓글 수: 2
Igor Dakic
Igor Dakic 2019년 6월 8일
Thanks! Is it possible to avoid loops and vectorize parts for value_inner_integral(i) and g(i)?
Torsten
Torsten 2019년 6월 11일
For "value_inner_integral", the answer is no.
For "driver_fun_g": If you can evaluate g for arrays of x1, x2 x3 and y4, the answer is yes.

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by