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

5 ビュー (過去 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 Center および File ExchangeShifting 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