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

2 visualizaciones (últimos 30 días)
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?

Respuesta aceptada

Alan Stevens
Alan Stevens el 29 de Nov. de 2022
Editada: Alan Stevens el 29 de Nov. de 2022
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 comentario
Saeid
Saeid el 29 de Nov. de 2022
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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Mathematics en Help Center y File Exchange.

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by