I am looking to solve an economic system, using Matlab. It considers an industry of just 2 firms where the demand functions for Firm 1 and Firm 2 are:
$$q_1(p_1,p_2)=\alpha(p_1-\delta p_2)^{-\gamma},$$ $$q_2(p_1,p_2)=\alpha(p_2-\delta p_1)^{-\gamma}.$$
I also have the cost functions for each firm:
$$C_1(q_1)=\beta _1 \cdot q_1^\rho, $$
$$C_2(q_2)=\beta _2 \cdot q_2^\rho. $$
I have been given the values for all the parameters needed to solve it, in order to find the optimal prices $p_1$ and $p_2$. In this system, I am told that Firm 1 sets its price first, and Firm 2 chooses its price optimally after observing the price set by Firm 1. I just need some help on going about this question on paper, before I code it in Matlab. I understand that I need to find max the profit function of Firm 1, thus finding its output and then substitute that into the reaction function of Firm 2. However, I am not sure how to form each Firm's profit function in order to maximise them.
Edit: Following the replies, I formed the two profit functions for Firm 1 and Firm 2.
$$\Pi_1(p_1,p_2)=p_1\alpha(p_1-\delta p_2)^{-\gamma} -\beta _1[\alpha(p_1-\delta p_2)^{-\gamma}]^\rho$$ $$\Pi_2(p_1,p_2)=p_2\alpha(p_2-\delta p_1)^{-\gamma} -\beta _2[\alpha(p_2-\delta p_1)^{-\gamma}]^\rho$$
I now know that I need to find the maximum of $\Pi_2$ and rearrange for $p_2$ which would result in Firm 2's reaction function. I could then substitute this into $\Pi_1$ and hence find the maximum for that.
The problem is now that this is obviously something that needs to be solved numerically which is why I am using Matlab. I am told that I first need to form the Lagrangian function in order to find the max of $\Pi_2$. I know how to do this, however I am unsure of the constraint needed, since obviously you need a constraint in order to form the Lagrangian function. What would this constraint be so that I can begin forming the conditions needed?
Profit is revenue minus cost. Therefore, the profit function for Firm $1$ is $$\Pi_1 (p_1,p_2) = p_1 q_1 - C_1(q_1)$$ Replacing $q_1 (p_1,p_2)$, this gives $$\Pi_1 (p_1,p_2) = p_1 \alpha(p_1-\delta p_2)^{-\gamma} - \beta_1 \left[ \alpha(p_1-\delta p_2)^{-\gamma}\right]^\rho$$ The profit $\Pi_2 (p_1,p_2)$ for Firm 2 is defined similarly.
The model you describe is known as the Stackelberg model. In short, it is solved by solving for $$p^*_2(p_1) = \arg\ max_{p_2} \Pi_2 (p_1,p_2)$$ This is known as the best reply function of Firm 2 to the price $p_1$ of Firm 1.
This is substituted back into $\Pi_1$ to solve $$\max_{p_1} \Pi_1 (p_1, p_2^*(p_1))$$ which gives the optimal price $p^*_1$ for Firm 1. Once this is established, $p^*_2(p^*_1)$ gives the optimal price that will be charged by Firm 2 after observing $p^*_1$.