Why does integration of an exponential function generate noisy results as opposed to its analytical solution?
2 views (last 30 days)
Show older comments
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?
0 Comments
Accepted Answer
Alan Stevens
on 29 Nov 2022
Edited: Alan Stevens
on 29 Nov 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)
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!