Representative Agent and Maximization

If there's a maximization of utility subject to a budget constraint-would it be always a representative agent model? Can it be heterogenous in some cases?

tldr to have a representative consumer, indirect utility functions need to be of the Gorman polar form, which means that individual Engel curves are straight lines with common slopes. One particular instance of such Gorman polar form is when everyone has identical homogeneous utility, e.g. identical Cobb-Douglass utility functions. Another example is if everyone has quasi-linear utility.

Gorman Polar form

Usually individual demands do not aggregate into the demand of a representative consumer. In fact, the only preferences that do aggregate are of the so called Gorman polar form.

The Gorman polar form requires the indirect utility function (say of individual $$k$$) takes on the following functional form: $$v_k(p,m_k) = a_k(p) + b(p)m_k$$ Where $$m_k$$ is income of individual $$k$$ and $$p$$ are prices. Here $$a_k(p)$$ is a decreasing function of prices alone and may be individual specific (i.e. be different for different individuals), while $$b(p) > 0$$, which is also a decreasing function of prices has to be the same for all individuals.

Inverting this function with respect to $$m_k$$ gives the expenditure function: $$e_k(p,u) = \frac{-a_k(p) + u}{b(p)} = -\frac{a_k(p)}{b(p)} + \frac{u}{b(p)}$$ This shows that $$a_k(p)/b(p)$$ and $$1/b(p)$$ have to be homogeneous functions of degree $$1$$ in $$p$$.

Taking the derivative, say to $$p_i$$ gives the Hicksian demand for good $$i$$ of individual $$k$$: $$h_k(p) = \frac{-a_{k,i}(p) b(p) - (-a_k(p)+u)b_i(p)}{b(p)^2},$$ where we use the notation $$a_{k,i}(p)$$ for the partial derivative of $$a_k(p)$$ with respect to $$p_i$$ and $$b_i(p)$$ is the partial derivative of $$b$$ with respect to $$p_i$$.

Then substituting back the expenditure function gives the Marshallian demand function for good $$i$$ of individual $$k$$: $$q_k(p,m_k) = -\frac{a_{k,i}(p)}{b(p)} + \frac{-b_i(p)}{b(p)}m_k$$ Notice that this is a linear function which is linear in $$m_k$$ with slope $$-b_i(p)/b(p)$$ which is the same over all individuals. So Engel curves are straight lines with identical slopes.

Aggregate (Marshallian) demand is obtained by summing $$q_k(p,m_k)$$ over all consumers $$k$$: $$\sum_k q_k(p,m_k) = -\sum_{k} \frac{a_{k,i}(p)}{b(p)} + \frac{b_i(p)}{b(p)}M$$ where $$M = \sum_k m_k$$ (this can also be obtained by immediately using Roy's identity on the indirect utility function). Notice that the right hand side only depends on total income $$M$$ and not on the particular way income is distributed across individuals. As such, we can denote this aggregate demand as $$Q(p,M)$$.

Moreover using a similar reasoning as above, one can show that $$Q(p,M)$$ is the demand function of a representatitve consumer with preferences: $$V(p,M) = \sum_k a_k(p) + b(p) M$$ So if everyone has preferences of the Gorman Polar form, then there is an aggregate consumer with preferences that can be obtained by taking the sum of the individual indirect utility functions.

Homothetic preferences and Quasi-linear preferences

In general, it is not possible to invert the Gorman polar form for $$v_k(p,m_k)$$ to obtain a functional form for the direct utility function $$u_k(q)$$. So it is not known what conditions need to be imposed on the direct utility function to obtain a representative consumer.

However, two special cases of the Gorman polar form is when $$a_k(p) = 0$$ for all $$k$$. In this case: $$v_k(p,m_k) = b(p)m_k,$$ which coincides with homothetic utility function. This gives rise to linear Engel curves through the origin, with the same slope over all individuals. So if everyone has identical and homothetic utility functions, e.g. Cobb-Douglass, then there is a representative consumer. Using Roy's identity gives: $$x(p,m_k) = \frac{-b_i(p)}{b(p)} m.$$ Aggregate demand are then given by: $$Q(p,M) = -\frac{b_i(p)}{b(p)} M.$$

Another case is where $$b(p) = 1$$ which gives: $$v_k(p, m_k) = a_k(p) + m$$ This is the indirect utility function of a person with quasi-linear utility. In this case, the Engel curve is a straight line with a unit slope. Using Roy's identity, we obtain for the individual demands: $$q_k(p,m_k) = - a_{k,i}(p)$$ which does not depend on income (as we have quasi-linear utility). Then aggregate demand gives $$Q(p,M) = -\sum_k a_{k,i}(p)$$ which is just a constant function.

If there's a maximization of utility subject to a budget constraint-would it be always a representative agent model? Can it be heterogenous in some cases?

Yes, it trivially can be heterogenous in some cases. You can have utility maximization problems subject budget constraints that are not representative agent problems. You can have heterogenous agents utility maximization problems with budget constraints as well. A trivial example would be simple modification of 2 good, 2 state, 2 consumer pure exchange model where first consumer would be assumed to have utility $$u(x_1,x_2) = Ax_1^{0.5}x_2^{0.5}$$ and second let's say $$u(x_1,x_2) = Bx_1^{0.1}x_2^{0.9}$$ both subject to budget constraint given by their endowments. This would be utility maximization problem, with budget constraints but without representative agents.