       Re: Fw: Integrate...

• To: mathgroup at smc.vnet.net
• Subject: [mg44370] Re: Fw: Integrate...
• From: "David W. Cantrell" <DWCantrell at sigmaxi.org>
• Date: Fri, 7 Nov 2003 05:16:13 -0500 (EST)
• References: <bob5ac\$qd3\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```"Christos Argyropoulos M.D." <argchris at otenet.gr> wrote:
> I think the problem goes deeper than simply mixing symbolic/numerical
> stuff.

You're absolutely right. Of course, what Jens-Peer said, seconded by
Curt, is good advice. But it in no way explains the huge discrepancy
between the incorrect -2.82839 and the correct 0.000037373 .

> Try symbolic integration of the original function
[snip]
> Results of the original, simplified versions and the numerical
> integration agree for 0<=a<=2.35 and 0<=b<2.35
> After they diverge dramatically. I suspect this is a bug somewhere
> inside Integrate, but I do not have the guts to evaluate the
> integral by hand to see, if the expression returned for symbolic a,b
> are correct.

I guess that depends on your precise definition of "bug".

Here's what's going on:

Integrate[Abs[Cos[r] + Sin[r]], {r, a, b}]  gives a messy expression. Then

Assuming[a >= 0 && b > a, FullSimplify[%]]  yields

((-a + b)*(((-Cos[a] + Sin[a])*Sqrt[1 + Sin[2*a]])/
(Cos[a] + Sin[a]) + ((Cos[b] - Sin[b])*
Sqrt[1 + Sin[2*b]])/(Cos[b] + Sin[b])))/(a - b)

(*  Aside: Why on earth, since I had specified that b > a, doesn't
FullSimplify cancel (-a + b) with (a - b) to give just -1 ?  *)

Next

% /. {a -> 235/100, b -> 236/100} gives a slightly messy, exact expression,
after which

N[%]  yields the absurd result of  -2.82839 .

The problem lies in the fact that the result given for the definite
integral with symbolic limits is incorrect (in the same way that I
discussed in my first response to Selwyn in the recent thread "Integrate
5.0"). Namely, although the integrand is _continuous_, Mathematica's
antiderivative is not, having spurious discontinuities. One of those lies
at 3*Pi/4, which is between 2.35 and 2.36. It is the source of the absurd
result, which is then, not accidentally, very close to -2*Sqrt.

An antiderivative for Abs[Cos[x]+Sin[x]] which is continuous for all real
x, obtained by hand, is

Sqrt(2 Floor[x/Pi + 1/4] - (-1)^Floor[x/Pi + 1/4]Cos[x + Pi/4])

Of course, having that, one can easily write an expression for the definite
integral with symbolic limits which is valid for _all_ real a and b. It's
too bad that Mathematica can't do that itself.

David Cantrell

> ----- Original Message -----
> From: "Sampo Smolander" <sampo.smolander+news at helsinki.fi>
To: mathgroup at smc.vnet.net
> Subject: [mg44370] Integrate...
>
> > Does anybody know why
> >
> >    Integrate[Abs[1.0*Cos[r] + 1.0*Sin[r]], {r, 2.35, 2.36}]
> >
> > gives
> >
> >    -2.82839
> >
> > whereas without those 1.0's,
> >
> >    Integrate[Abs[Cos[r] + Sin[r]], {r, 2.35, 2.36}]
> >
> > gives the correct
> >
> >    0.000037373

```

• Prev by Date: Re: Where to reply to...
• Next by Date: Re: Trying to use Mathematica as "word processor" for my math homework
• Previous by thread: Re: Fw: Integrate...
• Next by thread: Re:simple equation system -- crashing M5?