I am trying to integrate the following function,
f(r)=(80.50305990274495 - 35.03089630981622 r)/(80.50305990274495 -
79.5030598897815 r - r^2)
(* where r =[0,1] *)
The correct answer could be obtained by using NIntegrate
command in Mathematica and it gave 13.027. The NIntegrate
command always gave me 13.027 no matter what method I specify to integrate the integrand.
My main aim is to use Gauss Quadrature or other quadrature rules to get the correct result. Mathematica has a built-in command GaussianQuadratureWeights
which generates the sampling points and the weights in an interval. Using following code I tried to integrate the function, f(r) using Gauss quadrature rule but i am not getting the correct result and the Reason is presence of singularity at one of the end points (r=1) due to which the convergence is very slow.
nof=1500;
f= (80.50305990274495` - 35.03089630981622` r)/(80.50305990274495` -
79.50305988978158` r - 1.` r^2) ;
gq = GaussianQuadratureWeights[nof, 0, 1];
xi = gq[[All, 1]];
wi = gq[[All, 2]];
sol = Sum[wi[[y]]*(f /. {r -> xi[[y]]}), {y, 1, nof}];
Ans: 9.24379 (which is not correct) Can anyone help me with this? Thanks ashu
3.50774*10^9
atr -> 1
, which contributes to the slow convergence of a straightforward rule application.NIntegrate
overcomes this by subdividing the interval several times nearr == 1.
. You seem to appreciate this, but the implication is that the sampling has to be very high nearr == 1.
You might also need to increase the working precision to avoid roundoff error. $\endgroup$80.50305990274495
and (1+79.50305988978158
), which is ~10^-8. You are really pushing things trying to do this with machine precision. $\endgroup$r == 1
(exactly) and not a little outside the interval, then you cannot assign a numeric value to the integral. It is a simple pole at the end point of the interval, and AFAIK, no regularization or principal value can be applied to yield a value. $\endgroup$