Numerical integration and processing time

2 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 MATLAB 的更多信息

产品


版本

R2013a

Community Treasure Hunt

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

Start Hunting!

Translated by