Why does integration of an exponential function generate noisy results as opposed to its analytical solution?

1 次查看(过去 30 天)
The above question is of course a bit too general, but basically it would be of great advantage to find a way to ensure that numerical integration of a fraction that has an exponential function in its numerator consistently produces reliable results.
According to Gradshteyn and Ryzhik, the following correlation exists for the exponential integral:
When I try to calculate the integral on the right hand side unsing MATLAB's numerical integration, and check the result by comparing it to the analytical formula (i.e. exp(-x)*ei(x)-1/x obtained from the above equation) the result is very noisy. Here is the script:
clc; format long g; clear all; close all;
x=linspace(0.01,2,100);
for ii=1:length(x)
fun = @(t) exp(-t)./(x(ii)-t).^2;
y(ii) = integral(fun,0,Inf,'RelTol',1e-8);
Y(ii) = exp(-x(ii))*ei(x(ii))-1/x(ii);
end
plot(x,y,'k-',x,Y,'r-','linewidth',1.5)
Y is the analytical calculation and y is the result of direct numerical integration of the function exp(-t)/(x-2)^2 between 0 and infinity.
Is there a way to change MATLAB's numerical integration parameters to improve the quality of this group of integrals?

采纳的回答

Alan Stevens
Alan Stevens 2022-11-29
编辑:Alan Stevens 2022-11-29
You have a singularity when t = x(ii). Here's a rough and ready way to do the numerical integral (hmm! not sure the result is correct though!)
x=linspace(0.01,2,100);
d = 10^-8;
for ii=1:length(x)
fun = @(t) exp(-t)./(x(ii)-t).^2;
hi1 = x(ii)-d;
lo2 = x(ii)+d;
ylo = integral(fun,0,hi1,'RelTol',1e-8);
y(ii) = integral(fun,lo2,Inf,'RelTol',1e-8) + ylo;
end
plot(x,y,'k-','linewidth',1.5)
  1 个评论
Saeid
Saeid 2022-11-29
Hi Alan,
thanks for the comment. At least now the result is not noisy, but comparing it with the semi-analytical one shows that only one of these solutions is right. I cannot understand what is going on in here

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by