# wrong solution for double integral of piecewise function?

Discussion in 'Mathematica' started by Tom Roche, Feb 28, 2009.

1. ### Tom RocheGuest

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?

Tom Roche, Feb 28, 2009

2. ### Tom RocheGuest

Tom Roche Feb 28, 6:43 am
Bob Hanlon
and he points out that the proper way to do this is by wrapping an
Assuming around the procedure above:

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

produces

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

Thanks!

Tom Roche, Mar 1, 2009

3. ### Sjoerd C. de VriesGuest

Tom,

Why didn't you look up UnitStep? One press on F1 (PC) and you're done.
It shows you that the answers are the same if a<b. I guess you have