Bug or feature? If statement inside double integrals

106 Views Asked by At

Generally speaking,

$$ \int_c^a f(x) dx = \int_c^{a-b} f(x) dx + \int_{a-b}^a f(x) dx$$

However, consider the following Mathematica code: Code

So apparently, the sum of the two sub-integrals $1/32 + 0 = 1/32$ does not equal the base-integral $-3/32$.

Am I invoking the functions in a wrong way? Should I not use If statements inside integrals?

1

There are 1 best solutions below

2
On

The first integral is clearly false. You cannot integrate non-negative functions and get a negative result. (Moreover I believe that this is a joint pdf and you are trying to calculate the probability $P(Y>X+1/2)$. Did I find it?)

The problem is that the program puts $$i[y]=1$$ for all $x+1/2<y<1$ which is obviously not correct, since at some point $x+1/2$ exceeds $1$ and $i[y]$ must become zero (exactly at the point $b=1/2$ where you split later). So, the problem is that the program does not evaluate correctly $i[y]$ in the first case. Perhaps it is this with the if statement inside the integrals that you say yourself. When you split later in $1/4$ to $1/2$ and $1/2$ to $1$ you get the correct result.