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