<s>[INST] Integrating a function over a domain How could you integrate the function $f(x,y) = x^2 + y^2$ over the triangle with vertices $(0,0)$, $(0,1)$ and $(1,0)$?

I define the set $D = \{(x,y)\; |\;  0\leq x\leq 1  \text{ and } 0\leq y\leq x\}$ and then calculate
$$\int_0^1   \int_0^x   x^2 + y^2   \; \mathrm{d}y \; \mathrm{d}x = \frac{1}{3},$$
but apparantly the answer is $\frac{1}{6}$.
 [/INST] I think you have the limits changed and wrong. I think it must be
$$\int_0^1dx\int_0^{1-x}(x^2+y^2)dy=\int_0^1\left.\left(x^2y+\frac{1}{3}y^3\right|_0^{1-x}\right)dx=\int_0^1\left(x^2(1-x)+\frac{1}{3}(1-x)^3\right)dx=$$
$$=\frac{1}{3}-\frac{1}{4}-\frac{1}{12}(0-1)=\frac{2}{12}=\frac{1}{6}$$
</s>