MATLAB: Integrate function

functioninfinityintegratequadgk

Hey,
i want to integrate the function di on an interval from 1 to infinity. di=(sinh((b.*x)./a)./sinh((pi.*x)./a));
However while using quadgk matlab returns the following error code: Warning: Infinite or Not-a-Number value encountered.
Is there a possibility to change to change the code so maybe that it lowers accuracy however a result is obtained? Or is there another function that evaluates integrals up to infinity?
Thanks in advance.

Best Answer

The problem has nothing to do with the integrator, rather with the way you have written the integrand:
>> a = 1; b = 1;
>> di= @(x)(sinh((b.*x)./a)./sinh((pi.*x)./a));
>> di(1000)
ans =
NaN
You're giving the integrator NaN values, so there's not much it, or any other code, can do with that. Try multiplying your integrand numerator and denominator by exp(-pi*x) and simplifying. I get
>> dj= @(x)(exp((b-pi)*x) - exp(-(b+pi)*x))./(1-exp(-2*pi*x))
dj =
@(x)(exp((b-pi)*x)-exp(-(b+pi)*x))./(1-exp(-2*pi*x))
>> dj(1000)
ans =
0
>> quadgk(dj,1,inf)
ans =
0.051035297097439
-- Mike
Related Question