Bug? Analytical integration of cosines gets the sign wrong

Discussion in 'Mathematica' started by K, Feb 4, 2010.

  1. K

    K Guest

    Hello everyone,

    the analytical integration in Mathematica 7.01.0 on Linux x86 (64bit)

    faultyInt =
    Integrate[Cos[ph]*1/Pi*Cos[4*ph]*Cos[2*ph], {ph, Pi, 3/2*Pi}]

    gives as result:

    19/(105 \[Pi])

    which is as a decimal number

    N[faultyInt]

    0.0575989

    The numerical integration

    NIntegrate[Cos[ph]*1/Pi*Cos[4*ph]*Cos[2*ph],{ph,Pi,3/2*Pi}]

    gives

    -0.0575989

    which I believe is correct by judging from the plot

    Plot[Cos[ph]*1/Pi*Cos[4*ph]*Cos[2*ph], {ph, Pi, 3/2*Pi},
    PlotRange -> {-1/Pi, 1/Pi}]

    and because the quadgk function in another system gives the same
    negative result. Could anyone try this at home (or work, rather)
    and confirm or disprove it?
    Thanks,
    K.
     
    K, Feb 4, 2010
    #1
    1. Advertisements

  2. K

    Norbert P. Guest

    Not sure what's going on,
    but I' m getting the same thing on 7.0.1 on Win32:

    In[1] :=
    Integrate[Cos[ph]*1/Pi*Cos[4*ph]*Cos[2*ph], {ph, Pi, 3/2*Pi}]
    Out[1] = 19/(105 \[Pi])

    But the indefinite integral is correct:

    In[2] :=
    Integrate[Cos[ph]*1/Pi*Cos[4*ph]*Cos[2*ph],
    ph] /. {{ph -> 3/2 Pi}, {ph -> Pi}}
    Out[2] = {-(19/(105 \[Pi])), 0}

    In[3] := D[Integrate[Cos[ph]*1/Pi*Cos[4*ph]*Cos[2*ph], ph], ph] ==
    Cos[ph]*1/Pi*Cos[4*ph]*Cos[2*ph] // FullSimplify
    Out[3] = True

    Best,
    Norbert
     
    Norbert P., Feb 5, 2010
    #2
    1. Advertisements

  3. K

    DC Guest

    Same system, same result, but

    In[6]:= int = Integrate[Cos[ph]*1/Pi*Cos[4*ph]*Cos[2*ph], ph]

    Out[6]= (2 Sin[ph] + 2/3 Sin[3 ph] + 2/5 Sin[5 ph] +
    2/7 Sin[7 ph])/(8 \[Pi])

    In[8]:= (int /. ph -> 3/2 Pi) - (int /. ph -> Pi)

    Out[8]= -(19/(105 \[Pi]))

    -Francesco
     
    DC, Feb 5, 2010
    #3
  4. K

    ADL Guest

    On my version (7.0 for Microsoft Windows (32-bit) (February 18, 2009))
    I get the same issue.

    Moreover, it is very specific to the functional form, so that it
    appears to be an algebraic error.
    Or, perhaps, it's a feature...

    ADL
     
    ADL, Feb 5, 2010
    #4
  5. I get the same on my winxp32 machine. Looks like a bug to me...

    Cheers -- Sjoerd
     
    Sjoerd C. de Vries, Feb 5, 2010
    #5
  6. K

    Fred Guest

    K,

    I get the same wrong answer with Mathematica 7.0.1.0 under Windows 64-bit

    In[1]:=
    f[x_] = Cos[x]*Cos[2*x]*Cos[4*x]/Pi;
    Integrate[f[x], {x, Pi, 3 Pi/2}] // N
    NIntegrate[f[x], {x, Pi, 3 Pi/2}]

    Out[2]= 0.0575989
    Out[3]= -0.0575989

    Mathematica does get it right if we use indefinite integral

    In[4]:=
    fPrim[x_] = Integrate[f[x], x];
    fPrim[3 Pi/2] - fPrim[Pi] // N

    Out[5]= -0.0575989

    Mathematica even gets it right if we use the definite integral with bounds
    not involving Pi?

    In[6]:=
    lowerbound = 3.141592654;
    upperbound = 3 lowerbound/2;
    Integrate[f[x], {x, lowerbound, upperbound}] // N

    Out[8]= -0.0575989

    IMHO this is a bug, and should be reported to http://support.wolfram.com/submitabug.cgi

    Regarde Arnold Smit
     
    Fred, Feb 5, 2010
    #6
  7. K

    WetBlanket Guest

    If One substitutes the sequence, {1.9, 1.99, 1.999, ... 2.0}
    Mathematica gets the correct answer for as long as I tried except, of
    course for 2.0.
     
    WetBlanket, Feb 10, 2010
    #7
  8. K

    DrMajorBob Guest

    That's a VERY simple integrand; for Mathematica to get it wrong is
    worrisome.

    Below is an analytical confirmation of the NIntegrate result.

    expr = Cos[ph]*1/Pi*Cos[4*ph]*Cos[2*ph];
    Integrate[expr, {ph, Pi, 3/2*Pi}]

    19/(105 \[Pi])

    expr2 = Cos[ph]*1/Pi*Cos[4*ph]*Cos[2*ph] // TrigReduce
    Integrate[expr2, {ph, Pi, 3/2*Pi}]

    (Cos[ph] + Cos[3 ph] + Cos[5 ph] + Cos[7 ph])/(4 \[Pi])

    -(19/(105 \[Pi]))

    Bobby

     
    DrMajorBob, Feb 11, 2010
    #8
  9. K

    Louis Talman Guest

    Actually, something very strange---even stranger than has already been
    pointed out---is going on.

    Try, in version 7 of Mathematica (be prepared to wait a little while):

    --------------------
    f[x_] := Integrate[Cos[ t ] Cos[ 2 t ] Cos[ 4 t ], { t, Pi, x }]

    Plot[ f[x], {x, Pi, 2 Pi}, PlotRange -> All ]
    --------------------



    Then compare the resulting plot with the one obtained from

    --------------------
    F[x_] = Integrate[ Cos[ x ] Cos[ 2 x ] Cos[ 4 x ], x]

    Plot[ F[x] - F[Pi], { x, Pi, 2 Pi}, PlotRange -> All ]
    --------------------

    On my PPC iMac running OS X, v10.5.8, the first plot is the reflection
    of the second plot about the x-axis.


     
    Louis Talman, Feb 11, 2010
    #9
  10. K

    Tony Harker Guest

    This looks like a bug, and one that crept in between versions 6 and 7.
    Interestingly,

    Integrate[
    TrigExpand[Cos[ph]*1/Pi*Cos[4*ph]*Cos[2*ph]], {ph, Pi, 3/2*Pi}]

    gives the right answer [7.0 for Microsoft Windows (32-bit) (February 18,
    2009)].

    Tony

    ]-> -----Original Message-----
    ]-> From: WetBlanket [mailto:]
    ]-> Sent: 10 February 2010 08:35
    ]-> To:
    ]-> Subject: Re: Bug? Analytical integration of
    ]-> cosines gets the sign wrong
    ]->
    ]-> > Hello everyone,
    ]-> >
    ]-> > the analytical integration in Mathematica 7.01.0 on Linux
    ]-> x86 (64bit)
    ]-> >
    ]-> > faultyInt =
    ]-> > Integrate[Cos[ph]*1/Pi*Cos[4*ph]*Cos[2*ph], {ph, Pi, 3/2*Pi}]
    ]-> >
    ]-> > gives as result:
    ]-> >
    ]-> > 19/(105 \[Pi])
    ]-> >
    ]-> > which is as a decimal number
    ]-> >
    ]-> > N[faultyInt]
    ]-> >
    ]-> > 0.0575989
    ]-> >
    ]-> > The numerical integration
    ]-> >
    ]-> > NIntegrate[Cos[ph]*1/Pi*Cos[4*ph]*Cos[2*ph],{ph,Pi,3/2*Pi}]
    ]-> >
    ]-> > gives
    ]-> >
    ]-> > -0.0575989
    ]-> >
    ]-> > which I believe is correct by judging from the plot
    ]-> >
    ]-> > Plot[Cos[ph]*1/Pi*Cos[4*ph]*Cos[2*ph], {ph, Pi, 3/2*Pi},
    ]-> > PlotRange -> {-1/Pi, 1/Pi}]
    ]-> >
    ]-> > and because the quadgk function in another system gives the same
    ]-> > negative result. Could anyone try this at home (or work, rather)
    ]-> > and confirm or disprove it?
    ]-> > Thanks,
    ]-> > K.
    ]-> If One substitutes the sequence, {1.9, 1.99, 1.999, ... 2.0}
    ]-> Mathematica gets the correct answer for as long as I tried
    ]-> except, of
    ]-> course for 2.0.
    ]->
    ]->
     
    Tony Harker, Feb 11, 2010
    #10
  11. Plot[f[x] // Evaluate, {x, Pi, 2 Pi}, PlotRange -> All]

    would plot much quicker because it evaluates the Integrate once and for all
    inside the Plot.

    Alternatively, omit the // Evaluate, and use = rather than := in the
    definition of f[x], which evaluates the Integrate once and for all in the
    definition of f[x].

    --
    Stephen Luttrell
    West Malvern, UK

     
    Steve Luttrell, Feb 14, 2010
    #11
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.