From utility function (3 products) to demand function (2 products) I am struggling with this exercise and would appreciate some help. 
Consider two goods and a representative consumer whose utility is given by:
$U(q_{0}, q_{1}, q_{2})= q_{0}+5q_{1}+5q_{2}-\frac{1}{2}((q_{1})^{2}+(q_{2})^{2}+2dq_{1}q_{2})$
located with unit density on a road with unit distance. Consider two firms producing each good and having unit marginal cost.
I need to compute the demand and inverse demand functions and say when they are complements or substitutes. 
I do not know really how to set the income constraint because it says two goods but then there are three variables. Any hints?
Thanks a lot.
 A: In this case, $q_0$ is all of the "outside" goods, that is, the more it is consumed, the higher the utility will be. This is because the utility function is monotonically increasing in $q_0$, which suggests that the budget constraint should be 
\begin{equation}
q_0 + p_1 q_1 + p_2 q_2 \le Y
\end{equation} 
for budget level of $Y$, and prices of $p_1$ and $p_2$ for the good 1 and good 2. By using Lagrangian method or considering that a rational customer would spend all its budget, we can set $q_0 = Y- p_1 q_1 - p_2 q_2$. Plugging this back into the utility function, one needs to solve the following maximization problem
\begin{equation}
\max_{q_1,q_2}  (Y- p_1 q_1 - p_2 q_2) + 5q_1+5q_2−\frac{1}{2}(q_1^2+q_2^2+2dq_1q_2).
\end{equation}
First order conditions then suggest that
\begin{align}
q_1^*(p_1,p_2) &= \frac{5(1-d)-p_1+dp_2}{1-d^2} \\
q_2^*(p_1,p_2) &= \frac{5(1-d)-p_2+dp_1}{1-d^2}.
\end{align}
These are well-known linear demand functions and the cross-price effects are given as 
\begin{align}
\frac{\partial q_1}{ \partial p_2} = \frac{\partial q_2}{\partial p_1}=\frac{d}{1-d^2}.
\end{align}
Hence, these two goods are substitutes if $\frac{d}{1-d^2}>0$. They are complements if $\frac{d}{1-d^2}<0$.
