Let $\mu$ be a Borel measure on $\mathbb{R}$ defined by $\mu(x)=\begin{cases} x^2-1 & x\ \leq 0 \\ x^2 & x > 0\\ \end{cases}$
and let $f(x)=\begin{cases} 2 & x\in \mathbb{Q}\cap [-2,1] \\ 4 & x\in [-2,1] \setminus\mathbb{Q} \\ 0 & x\notin [-2,1] \\ \end{cases}$
Use the definition of Lebesgue integral for simple functions to calculate $\int_{\mathbb{R}} f(x) \mu(dx)$
Is this the proper way to calculate this?
$\int_{\mathbb{R}} f(x) \mu(dx)$ = $\int_{[-2,1]} fd\mu = \int_{[-2,1]\cap\mathbb{Q}} fd\mu + \int_{[-2,1]\setminus\mathbb{Q}} fd\mu + \int_{[-\infty,2)\cup(1,\infty]} fd\mu$
where $$\int_{[-2,1]\cap\mathbb{Q}} fd\mu = \int2\mu([-2,1]\cap\mathbb{Q}) = \int2(x^3)dx$$ $$\int_{[-2,1]\setminus\mathbb{Q}} fd\mu = \int3\mu([-2,1]\setminus\mathbb{Q}) = \int3(x^3)dx$$ $$\int_{[-\infty,2)\cup(1,\infty]} = \int 0\mu([-\infty,2)\cup(1,\infty]) = \int0(x^2-1)dx$$
No, you have to realize that $\mathbb Q$ is a null-set. This means that $\mu([-2,1]\cap \mathbb Q) \le \mu(\mathbb Q) = 0$. Also it means that $\mu([-2,1]\setminus \mathbb Q) = \mu([-2,1])$.
Also I think that $\mu(x)=...$ means that $\mu(E) = \int_E \mu(x)dx$. Your integral for the second part looks odd. I'd get it to:
$$\int_[-2,1]\setminus Q f d\mu = \int_{-2}^1 f d\mu = \int_{-2}^04(x^2-1)dx + \int_0^1 4x^2dx$$
for the third the result is correct, but you can directly use that the integral of a zero-function is always zero.