1
$\begingroup$

I want to plot a piecewise function with two variables using Manipulate command, but I am having trouble with it.

The function I want to plot is profit1. (details of the code can be found below)

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]], p2 == p1}, {Min[x2, Max[0, 1 - p2 - x1]], p2 > p1}}];
profit1 = (p1 - c)*z1;
profit2 = FullSimplify[Integrate[1 - z, {z, 0, z1 + z2}] - c (z1 + z2)];

Values of x1, x2, and c are known and as follows: x1 = 1; x2 = 0.4; c = 0

So profit1 becomes: profit1

When I try to use Manipulate to plot profit one:

Manipulate[Plot[profit1, {p1, 0, 1}], {p2, 0, 1}]

enter image description here

I get an empty graph like the one above. Any recommendations on how to fix this problem?

Thank you very much in advance.

$\endgroup$
1
  • $\begingroup$ You have to define functions, e.g., profit1[p1_, p2_] := ... $\endgroup$ Commented Dec 22, 2016 at 22:34

1 Answer 1

5
$\begingroup$
profit1[p1_, p2_] := Which[
   p1 < p2, Min[1, 1 - p1], 
   p1 == p2, Min[1, Max[.6 - p1, (1 - p1)/2]], 
   p1 > p2, Min[1, Max[0, .6 - p1]],  
   True,  0];

Manipulate[
 Plot[profit1[p1, p2], {p1, 0, 1}],
 {p2, 0, 1}]

Incidentally, you might find this figure helpful:

Plot3D[profit1[p1, p2], {p1, 0, 1}, {p2, 0, 1},
       PlotPoints -> 50]
$\endgroup$
2
  • $\begingroup$ That solves it, thank you very much! $\endgroup$
    – Elif
    Commented Dec 23, 2016 at 0:46
  • 1
    $\begingroup$ @Elif: If my solution "solve it," then please accept it by clicking the check mark. Thanks. $\endgroup$ Commented Dec 23, 2016 at 1:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.