Finding marginal density from a joint density when range of random variables are dependent on one another. I have two joint density problems, where I would like to find the marginal density.
The first one: $f(x,y) = 24xy, 0 \leq x \leq 1, 0 \leq y \leq 1, 0 \leq x+y \leq 1$
So, I "integrate out y" and get $f_x(x)=\int_{-\infty}^{\infty} 24xydy =12x $
I don't feel like this is right because I no longer have an handle on the extra condition of $x+y\leq1$, and if I integrate $12x$ over $[0,1]$, I just would get 6, instead of 1.
The second one: $\frac{1}{8}(y^2-x^2)e^{-y} -y \leq x \leq y, 0 < y < \infty$
Again, integrating out the y here seems to be the wrong approach because I'm not taking into consideration the relationship between x and y.
How would I proceed then in these two cases to find the marginal densities?
Thanks!
 A: 
As explained several times on the site, writing down correctly the joint density (1) and then, applying universal identities (2), saves any kind of head-scratching and ensures that one finds the correct answer (pretty boring, eh...).

(1) In the present case, the first step is to be aware that every two-dimensional density is always defined on the whole plane $\mathbb R^2$. In practice, this means that one should avoid every kind of auxiliary condition written on the side that one does not know how to deal with afterwards, and instead, write down the joint density as a function $$f_{X,Y}:\mathbb R^2\to\mathbb R.$$ Here, for every $(x,y)$ in $\mathbb R^2$, $$f_{X,Y}(x,y)=24xy\mathbf 1_{0\lt x\lt1}\mathbf 1_{0\lt y\lt1}\mathbf 1_{0\lt x+y\lt1}.$$
(2) The second step is to use the fact that, for every joint density $f_{X,Y}$, the density $f_X$ is a function $$f_X:\mathbb R\to\mathbb R,$$ such that, for every $x$ in $\mathbb R$,  $$f_X(x)=\int_\mathbb Rf_{X,Y}(x,y)\mathrm dy.$$ No fancy complicated interval of integration, just a plain integral on the whole real line--and it works, always (I told you, boring...).
All this is automatic, hence we can put our brain in position ON only now, and try to find a simple expression for $$f_X(x)=\int_\mathbb R24xy\mathbf 1_{0\lt x\lt 1}\mathbf 1_{0\lt y\lt1}\mathbf 1_{0\lt x+y\lt1}\mathrm dy.$$ Factoring everything independent on $y$ yields $$f_X(x)=24x\mathbf 1_{0\lt x\lt1}\int_\mathbb Ry\mathbf 1_{0\lt y\lt1}\mathbf 1_{0\lt x+y\lt1}\mathrm dy.$$ Note that, for every $0\lt x\lt1$ (since for other values of $x$, one does not care), $$\int_\mathbb Ry\mathbf 1_{0\lt y\lt1}\mathbf 1_{0\lt x+y\lt1}\mathrm dy=\int_0^{1-x}y\mathrm dy=\tfrac12(1-x)^2,$$ hence, finally, the density $f_X$ is defined, for every $x$ in $\mathbb R$, by the identity $$f_X(x)=\tfrac12(1-x)^2\cdot24x\mathbf 1_{0\lt x\lt1}=12x(1-x)^2\mathbf 1_{0\lt x\lt1}.$$
(Oh, and I forgot: to make a détour by the CDF when one is given a joint PDF and one looks for a marginal PDF, is like passing by Mexico and Vancouver to go from New York to Boston. It works, but.)
Here is a hint for your second case: for every $(x,y)$ in $\mathbb R^2$, $$\mathbf 1_{-y\lt x \lt y}\mathbf 1_{y\gt0}=\mathbf 1_{y\gt|x|}.$$
A: $$f(x,y)=24xy$$
First integrate with respect to $y$, because $x+y \leq 1$ then $y$ goes from $0$ to $1-x$
$$\int_0^{1-x} 24xy dy=12x(1-x)^2$$
Second to check it's every okay we integrate with respect to $x$:
$$\int_0^1 12x(1-x)^2dx=1$$
As you thought when you are integrating you can take the variable out just when you have independence which if I'm not a mistake only happen when you have a squared domain. 
A: You can compute $F_X(t) = P(x<t)$.
$$F_X(t) = \int_0^t \left(\int_{0}^{1-x}f(x,y)dy \right)dx$$
 for $t\in [0,1]$, $F_X(t) = 0$ for $t<0$ and $F_X(t) = 1 $ for $t>1$. Then, $f_X(t) = F_X'(t)$ for all $t\in \mathbb{R}$, except for $t\in \{0,1\}$. Expected value $E[X]$ can now be easily computed.
The second case can be treated in the same way.
