# Evaluate definite integral numerically, where the function is indeterminate

3 views (last 30 days)
jake gamma on 30 May 2020
Answered: Walter Roberson on 30 May 2020
I'm trying to evaluate the following integral Suppose I define a function handle as
f = @(x) x.*cosh(x)./( sinh(x).*(cosh(Phi*x)).^2 );
and evaluate the integral as
I = integral(f,-inf,inf)
the result gives NaN.
This is because the function is indeterminate at -inf, 0 and inf. However, using l'Hopital's rule, one can verify that the function's limits at these points are 0, 1, and 0, respectively, and the integral is indeed finite.
What is the best way to evaluate integrals of this kind numerically in MATLAB?

Ameer Hamza on 30 May 2020
Edited: Ameer Hamza on 30 May 2020
If you have Symbolic toolbox, then you can try
syms x
Phi = 1;
f(x) = x.*cosh(x)./( sinh(x).*(cosh(Phi*x)).^2 );
y = vpaintegral(f, -inf, inf)
Result
y =
2.4674
Alternative solution using integral()
y = integral(@f, -inf, inf)
function y = f(x)
Phi = 1;
y = x.*cosh(x)./( sinh(x).*(cosh(Phi*x)).^2 );
y(isnan(y)) = 0;
end