       Re: wrong solution for double integral of piecewise

• To: mathgroup at smc.vnet.net
• Subject: [mg97000] Re: [mg96968] wrong solution for double integral of piecewise
• From: Bob Hanlon <hanlonr at cox.net>
• Date: Sun, 1 Mar 2009 04:58:05 -0500 (EST)
• Reply-to: hanlonr at cox.net

When you integrated by hand you assumed that b > a, Mathematica gives a more complicated result since it does not make that assumption unless you tell it to do so.

Clear[f]

f[x_, p_] =
Piecewise[{{k, {a <= x <= b, a <= p <= b}}}];

int = Integrate[f[x, p],
{x, -Infinity, Infinity},
{p, -Infinity, Infinity}]

Piecewise[{{k*(a - b)^2,
a - b < 0}}, 0]

Simplify[Reduce[int == 1], b > a] // ToRules

{k -> 1/(a - b)^2}

The UnitStep expression is equivalent to the Piecewise expression

expr = {k -> -(1/((a - b)^2 (-1 + UnitStep[a - b])))};

Simplify[expr, b > a]

{k -> 1/(a - b)^2}

You can include the assumption with the integral

Assuming[{b > a}, Integrate[f[x, p],
{x, -Infinity, Infinity},
{p, -Infinity, Infinity}]]

k (a-b)^2

Integrate[f[x, p],
{x, -Infinity, Infinity},
{p, -Infinity, Infinity},
Assumptions -> {b > a}]

k (a-b)^2

Bob Hanlon

---- Tom Roche <tlroche at gmail.com> wrote:

=============
wrong solution for double integral of piecewise function

I've got a function

f[\[Chi]_, \[Psi]_] =
{Piecewise[{{k, {a <= \[Chi] <= b, a <= \[Psi] <= b}}}, 0]}

I'm attempting to solve for k such that f becomes a probability
density function by applying the normalization constraint, i.e.
solving for k such that the double (indefinite) integral of f equals
1. I can do this by hand pretty easily, integrating first/inside WRT
psi and second/outside WRT chi, and I get

(1) k = 1/((b-a)^2)

I don't have the world's greatest calculus chops, but that looks
correct to me. (Am I missing something?) However, when I use
Mathematica to

Solve[
First[
Integrate[
Integrate[
f[\[Chi], \[Psi]], {\[Psi], -\[Infinity], \[Infinity]}
],
{\[Chi], -\[Infinity], \[Infinity]}
]
] == 1, k
]

I get

(2) {{k -> -(1/((a - b)^2 (-1 + UnitStep[a - b])))}}

which seems wrong to me, though I'll admit I don't know what
"UnitStep" means. So I'm wondering

* does (1) = (2)? or

* have I made a syntax error? or

* is this just really hard to solve symbolically? If so, is there a
better way to setup this function and its solution?

• Prev by Date: Re: Exporting data into a file, OpenWrite
• Next by Date: Re: Need some help with monitoring evaluation
• Previous by thread: Re: Exporting data into a file, OpenWrite
• Next by thread: Re: Need some help with monitoring evaluation