# Simultaneous Maximization of two Functions

I am a new Mathematica user, and I apologize in advance if my question is too trivial. I could not find a solution to my problem in Mathematica tutorials, so I came here to ask.

I am trying to find the nash equilibrium in a duopoly setting where firms are profit maximizers.

Sales of firms are given as:

z1 = Piecewise[{{Min[x1, 1 - p1] ,
p1 < p2}, {Min[x1, Max[((1 - p1)/2), 1 - p1 - x2]],
p1 == p2}, {Min[x1, Max[0, 1 - p1 - x2]] , p1 > p2}}]

z2 = Piecewise[{{Min[x2, 1 - p2] ,
p2 < p1}, {Min[x2, Max[((1 - p2)/2), 1 - p2 - x1]],
p1 == p2}, {Min[x2, Max[0, 1 - p2 - x1]] , p2 > p1}}]


where p=price, x=capacity

Firm1 is trying to maximize profit1=p1*z1-x1^2 and has control over parameters x1 & p1.

Firm2 is trying to maximize profit2=p2*z2-x2^2 and has control over parameters x2 & p2.

As an initial step, I am interested in finding the maximum profit of each firm given capacities. So I want firm1 to maximize profit1 with respect to p1, and firm2 to maximize profit2 with respect to p2 simultaneously.

I tried computing

Solve[{D[profit1, p1] == 0, D[profit2, p2] == 0}, {p1, p2}]


but this method is not reliable since profits are piecewise functions. It does give a solution when capacities are symmetric, but returns null otherwise.

When I try using the Maximize function (which I am not sure if I am using correctly) I get an error.

I tried computing

Solve[{Maximize[profit1, p1], Maximize[profit2, p2]}, {p1, p2}],


this gives the following error:

Can anybody help me on simultaneous maximization of these two different functions?

Became too long for a comment:

I think I see the problem. You have previously assigned the symbols profit1 and profit2 values. You can see this because they are not highlighted in blue, but are instead black. Mathematica is treating these symbols as fixed numbers probably, and you need to run Clear[profit1,profit2] to fix this so you can use them as undefined symbols again. It may be the case that you have a similar problem with some of x1, x2, p1 and p2. Make sure these variables do not have assigned values before using them in something like Solve.

If you run the following, your output should match mine:

Clear[x1, x2, p1, p2, z1, z2, profit1, profit2];
z1 = Piecewise[{{Min[x1, 1 - p1],
p1 < p2}, {Min[x1, Max[((1 - p1)/2), 1 - p1 - x2]],
p1 == p2}, {Min[x1, Max[0, 1 - p1 - x2]], p1 > p2}}];

z2 = Piecewise[{{Min[x2, 1 - p2],
p2 < p1}, {Min[x2, Max[((1 - p2)/2), 1 - p2 - x1]],
p1 == p2}, {Min[x2, Max[0, 1 - p2 - x1]], p2 > p1}}];
profit1 = p1*z1 - x1^2;
profit2 = p2*z2 - x2^2;
Solve[{D[profit1, p1] == 0, D[profit2, p2] == 0}, {p1, p2}]


And no, it is not valid to use the Maximize function in the Solve function the way you have. Just because it makes sense in English doesn't mean it makes any sense from a programming perspective. Solve takes in a list of boolean expressions, and a list of variables with respect to which it solves. See the Documentation Center for more help. An easy way to do this is to highlight the function you're trying to use and press F1.

Now of course you have a point about the non-differentiability bit. First, I'll recap how we would solve this problem for a single continuous function of a single parameter. If we have a piecewise differentiable function $f(x)$ which is everywhere continuous, and we want to solve for a global extremum (i.e. minimum or maximum) then we do the following:

1. Check the extremum values in the differentiable regions.
2. Check the values at every $x$ where $f(x)$ is not differentiable.
3. Choose the largest of the values we've checked.

Here's an example function with the points we need to check highlighted.

Note that this assumes that the limits $x \rightarrow \pm \infty$ are not of interest.

So coming back to the problem at hand, we've only completed Step 1. We need to find out if for each profit1, profit2, the non-differentiable case is a local maximum.

I had thought of showing how to solve this manually, but the mathematical technique is not that complicated, but arduous (check sign of derivative on both sides of non-differentiable point) and really steps outside the scope of a Mathematica question. Hopefully someone else can show you a method of doing this a more elegant way within Mathematica.

• Hi, thanks a lot for your answer. I did get the same output as you before. But my problem is, derivation does not work when I want to examine optimal prices given asymmetric capacities x1 and x2. The profit function is in piecewise form, and undifferentiable at some points. That's why I am looking for a method different from setting the derivatives equal to zero. I understand that Maximize will not work, but is there any other function that would give me the equilibrium prices? – Elif Sep 15 '16 at 11:53
• @Elf - Could you explain what you mean by asymmetric values for x1 and x2? The example above does work for when they have different values. However, you are right about the non differentiable thing. I will think on this. – Myridium Sep 15 '16 at 11:56
• @Elif - You are trying to maximise two interdependent functions. You need a well-defined notion of what you mean by 'maximise'. What is it you are trying to maximise? First you need to know this yourself before you can have Mathematica do it. Solving for when the derivatives are both zero is something, as you're asking for locally stationary points. I can hazard a guess as to what you want: are you trying to solve for when a small shift in p1 or in p2 would reduce the value of both z1 and z2? – Myridium Sep 15 '16 at 12:01
• I am trying to find the points in which neither of the firms have an incentive to deviate, or in other words the equilibrium points. So given p2, firm1 will choose p1 so that it maximizes profit1; and given p1 firm2 will choose p2 so that it maximizes profit2. It's just that they do this simultaneously. My main objective is to see whether firms choose prices in such a way that z1 and z2 (sales) turn out to be less than x1 and x2 (capacities) in a repeated setting. But before coming to that, I need to figure out solving the game in this non-repeated form. – Elif Sep 15 '16 at 12:14
• @Elif - Ah, that firm1 had control of parameter p1 and firm2 control of parameter p2 was not obvious to me, thank you. Please consider adding this clarification to your question. I understand now. – Myridium Sep 15 '16 at 12:17