Numerical integration and processing time

2 ビュー (過去 30 日間)
Yassine Hmamouche
Yassine Hmamouche 2020 年 5 月 30 日
コメント済み: Walter Roberson 2020 年 6 月 1 日
Hello,
I need to evaluate the following integral A. So, I devided it into three functions as
The functions of interest are built as
function [out] = funct1(x,y)
ny=length(y);
out=zeros(1,ny);
for i=1:ny
S1=@(v,theta) v.*exp(-v).*exp(-sqrt(v.^2+x.^2-2.*x.*v.*cos(theta)));
S2=@(theta) exp(-sqrt(y(i).^2+x.^2-2.*x.*y(i).*cos(theta)));
out(i)=integral(S2,0,2*pi,'ArrayValued',true).*exp(-quad2d(S1,0,y(i),0,2*pi));
end
end
function [out] = funct2(x)
nx=length(x);
out=zeros(1,nx);
for i=1:nx
S3=@(y) y.*exp(-y).*funct1(x(i),y);
out(i)=integral(S3,0,inf,'ArrayValued',true);
end
end
function [out] = funct3(a)
S=@(x) funct2(x);
out=a*integral(S,0,inf);
end
One major problem is that such codes give a very delayed result with warning message as
tic
A=funct3(1)
toc
%%%%%%%%%%%%%%%%%%%%%
Warning: Reached the maximum number of function evaluations (10000). The result fails the global error test.
A =
2.3982
Elapsed time is 75.049599 seconds.
Any help please to reduce such processing delay and avoid the warning message.
Many thanks in advance.
  6 件のコメント
Walter Roberson
Walter Roberson 2020 年 5 月 31 日
For example for x = 10^5, then p4 works out as 6.6951418857737784647*10^(-43424)... after several hours.
Walter Roberson
Walter Roberson 2020 年 6 月 1 日
For the overall integral, coding in terms of vpaintegral() with RelTol 1e-4, then MATLAB comes up with 0.5485 after 14307 seconds (just under 4 hours)
The code was
syms x y v theta
assume(x>=0 & y>=0 & v >= 0 & theta >=0)
Int = @(F,var,lb,ub) vpaintegral(F, var, lb, ub, 'RelTol',1e-4);
p5 = Int(v*exp(-v)*exp(-sqrt(x^2 + v^2 - 2*x*v*cos(theta))), theta, 0, 2*pi);
p45 = Int(p5, v, 0, y);
p3 = Int(exp(-sqrt(x^2 + y^2 - 2*x*y*cos(theta))), theta, 0, 2*pi);
tic; p2 = Int(y*exp(-y)*p3*exp(-p45), y, 0, inf); toc
tic; p1 = Int(x*exp(-x)*p2, x, 0, inf); toc %4 hours !!!
digits(16);
tic; funct3 = vpa(p1); toc
disp(funct3)

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

回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

製品


リリース

R2013a

Community Treasure Hunt

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

Start Hunting!

Translated by