When n = 2 or 3, we can solve this integral by reducing the denominator to the form (x + a)^2 + B. What is the general procedure for evaluating such integrals for n > 3?
I don't know of any general method but what I would try is to see if the polynomial has some root among the divisors of a(n) and then use Ruffini method to decompose the polynomial into a product of two lower degree polynomials...
For symbolic integartion see the book by my late friend Manuel Bronstein. Now, the method I have been taught in school is to use partial fraction expansion over the reals and then integrate each term separately. Of course this suppose being able to factorize the polynomial in the denominator...
if p(x) is a polynomial with real coefficients, it can be factorized into linear and quadratic factors with real coefficients. if l1(x), l2(x)..., q1(x), q2(x).... are these factors, you can write 1/p(x) as b1/l1(x) + b2/l2(x) + ... + (c1 x + d1)/q1(x) + (c2 x + d2)/q2(x) + ..., then integrate each term separately, getting a sum of a whole bunch of log and arctan functions.
NB : p(x) can also be factorized into linear factors with complex coefficients, then your real integral 1/p(x) becomes a complex integral b1/l1(x) + b2/l2(x) + ... (no quadratic terms), which gives a bunch of log functions, some with complex arguments. The ones with complex arguments could be combined (in pairs) into a bunch of arctangent functions. Try this method too, and see which is easier.
Michael Hartley's answer seems right. But there is a problem: factorizing polynomials of degree more than 5 is difficult. How to get over this problem?
If you want a numerical solution to a definate integral, you could use Simpson's rule or some other quadrature rule. This can be made as precise as you want.
Or if you want an indefinite integral, you could still use numerical techniques to find the complex roots of the polynomial, and so factorise it.
Otherwise, often the roots of the polynomial are such that the simplest way to describe them is as the root of the polynomial. Eg, what are the roots of x^2-2 ? They are sqrt(2) and -sqrt(2). What's sqrt(2)? It's the positive root of the polynomial x^2-2. A bit circular, but not totally - we can, for example, say "let s be a root of x^2-2. Then, the other root is -s", or "let s be a root of x^2+x+1. Then, the other root is -1-s". You can do similar but more complicated tricks for higher degree polynomials, to get purely algebraic factorisations, perhaps even in cases where your a(i) are variables rather than given numbers.
If you need to implement this integral in software, I'd suggest using one of the first two methods.