Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

How to solve this integral in Mathematica

Is it possible to solve it numerically?

$$\begin{align} \int_{-1}^1 \cos\big(&(.75-.75x^2)\cdot y_1 + (.25 - .5x - .75x^2) \cdot y_2 \\ + &(-.5x + .5x^3) \cdot y_3 + (.125 - .75 x^2 + 0.625 x^4) \cdot y_4 \big) dx \end{align}$$

share|improve this question
Please put some effort into making the question readable. –  Mikael Öhman Dec 13 '11 at 14:01

1 Answer 1

up vote 3 down vote accepted

The short answer is No.
You can't have undefined symbols/variables in numerical integrals.

If you want a purely numerical solution, you could make a 4-dimensional grid that covers the range of $y_i$ that you're interested in, do the integrals at those points and interpolate between the results.
Or, more simply, just define a numerical integral function that you can call when ever you need the result (it's a simple integral, so it is quite fast).

nInt[y1_?NumericQ, y2_?NumericQ, y3_?NumericQ, y4_?NumericQ] := 
 NIntegrate[Cos[(.75 - .75 x^2) y1 + (.25 - .5 x - .75 x^2) y2
    + (-.5 x + .5 x^3) y3 + (.125 - .75 x^2 + 0.625 x^4) y4], 
   {x, -1, 1}]

You can then plot any section of the 4D function that you want. For example and no particular reason,

Plot[nInt[x, 2 x, 0, 1], {x, -1, 1}]


More interesting (to me) is how far you can get with this integral analytically. If you didn't have any $x^3$ or $x^4$ terms, then integral can be done completely in terms of Fresnel C and S functions (W|A).

Sqrt[2c/Pi] Integrate[Cos[a + b x + c x^2], {x, -1, 1}]//TraditionalForm


In general, it is a little more tricky. You could try a series expansion:

sc = Simplify[SeriesCoefficient[
  Cos[a + b x + c x^2 + d x^3 + e x^4], {x, 0, n}], n >= 0]

(* Integrate term by term. Sum can't be done by Mma *)
(*Sum[(1+(-1)^n)/(1+n) sc, {n, 0, Infinity}]*) 

(* but can expand up to any order *)
Table[(1 + (-1)^n)/(1 + n) sc, {n, 0, 10}] // ExpToTrig // 
  Simplify[#, Trig -> False] &

The SeriesCoefficient returns a DifferenceRoot expression - i.e., it can't be given in "closed form". Mathematica is then unable to compute the commented out Sum. However, you can get the expansion of the result to any order, the Table command returns

{2 Cos[a], 0, 1/3 (-b^2 Cos[a] - 2 c Sin[a]), 0, ...

If you think about a being dimensionless, b having dimension one, ..., e having dimension 4, then each term is of a fixed dimension. Note that odd terms in the series vanish (because of the symmetry of the integral).

This result can then be specialized to your particular values, e.g., a = .75 y1 + .25 y2 + .125 y4, etc...

share|improve this answer
I must try Simon. Really, answer is professional, better 100 times then my question. –  George Dec 13 '11 at 22:59

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.