Price mechanism question (economics) There are two goods in the market $X1$ and $X2$ and both of their prices are positive. If an agent's utility function is given as: Q1 = amount of X1 agent buys, Q2 = amount of X2 agent buys, $u = Q1 + |Q2-5|$ Identify the demand of this agent.
Note: agent has to spend his initial endowment. 
 A: Clearly it depend on the prices, say $P1$ and $P2$, and on the agent's endowment, say $m$.
There is no point in demanding $Q2 \gt 5$: utility would be increased reducing $Q2$ to $5$ and spending the saved amount on $X1$.
For small endowments the agent will maximise utility by spending on the good with the lower price.  Indeed if $P1 \lt P2$ it will always be better to buy more of $X1$ and none of $X2$.  And similarly if $P1 \gt P2$ it will be better to buy more of $X2$ and none of $X1$ until $Q2=5$.  So


*

*if $P1 \lt P2$, then demand is $Q1=m/P1$ of $X1$ and $Q2=0$ of $X2$

*if $P1 \gt P2$ and $m/P2 \le 5$, then demand is $Q1=0$ of $X1$ and $Q2=m/P2$ of $X2$

*if $P1 \gt P2$ and $m/P2 \ge 5$, then demand is $Q1=(m-5\times P2)/P1$ of $X1$ and $Q2=5$ of $X2$


If $P1=P2$ then there are several solutions which are convex combinations of those bullet points. 

Added much later 
Rereading this in the light of Amit's perceptive comment, I should have said something like: 
If $P1 \le P2$  it will always be better to buy more of $X1$ and none of $X2$, and this will also be the case with small endowments and $P1 \gt P2$: in either case you get a utility of $Q1+5$.
But for $P1 \gt P2$ and a large endowment $m$ the opposite is true and you can get a higher utility of $Q2-5$ when $m/P2 - 5 \gt m/P1 +5$, i.e. when $m \gt \frac{10\,P1\, P2}{P1-P2}$. So     


*

*if $P1 \le P2$ or $m \lt \dfrac{10 \,P1\, P2}{P1-P2}$, then demand is $Q1=m/P1$ of $X1$ and $Q2=0$ of $X2$

*if $P1 \gt P2$ and $m \lt \dfrac{10 \,P1\, P2}{P1-P2}$, then demand is $Q1=0$ of $X1$ and $Q2=m/P2$ of $X2$

*if $P1 \gt P2$ and $m = \dfrac{10\,P1\, P2}{P1-P2}$ then either all $X1$ and no $X2$ or no $X1$ and all $X2$ are both optimal

A: Let $p_1$, $p_2$ denotes the prices of $X_1$, $X_2$ respectively, and $m$ denotes the income of the consumer. Utility function of the consumer is given: $u(Q_1, Q_2) = Q_1 + |Q_2-5|$. Demand is the solution to the following problem:
\begin{eqnarray*} \max_{Q_1, Q_2} & & Q_1 + |Q_2-5| \\ \text{s.t.} && p_1Q_1 + p_2Q_2 = m \\ && Q_1 \geq 0, Q_2 \geq 0 \end{eqnarray*}
and it will be:
\begin{eqnarray*} (Q_1^d, Q_2^d)(p_1, p_2, m) = \begin{cases} \displaystyle\left(\frac{m}{p_1}, 0\right) && \text{ if }  p_1 \leq p_2 \\ \displaystyle\left(\frac{m}{p_1}, 0\right) && \text{ if }  p_1 > p_2 \text{ and } \displaystyle\left(\frac{m}{p_2} - \frac{m}{p_1}\right) \leq 10 \\ \displaystyle\left(0,\frac{m}{p_2}\right) && \text{ if }  p_1 > p_2 \text{ and } \displaystyle\left(\frac{m}{p_2} - \frac{m}{p_1}\right) \geq 10 \end{cases} \end{eqnarray*}
A: The consumer will simply compare between the utilities $\frac {M}{p_1} + 5$ and $\frac {M}{p_2}-5$
Now, $\frac {M}{p_1}+5 \gt \frac {M}{p_2} - 5 \implies \frac {M}{p_2}-\frac {M}{p_1}\lt 10$
