Message Boards Message Boards

0
|
12753 Views
|
4 Replies
|
1 Total Likes
View groups...
Share
Share this post:

How to compare two or even more piecewise functions to get a opitmal one?

Posted 11 years ago
How to compare two or even more piecewise functions to get a opitmal one?
I can get the result by hand calculation, but it is not very convenient, especially for many piecewise functions. I wonder if there is any simple command for mathematica to calculate it. In order to explain my question more clearly, the comparison of two piecewise fucntions is given below:
POSTED BY: Shaoyan Robert
4 Replies
Posted 11 years ago
Thank you, yehuda and Frank, your suggestion is very helpful. Actually, my question is going to find a optimal value w2 to maximize profit function:
 Clear["`*"];
 
 a = 10; b = 1; c = 2; v2 = 1; d2 = a - b*p2;
 
 Q1[w2_] =
 
  Maximize[{(p2*(a - b*p2) - (w2*(a - b*p2) - (v2*((a - b*p2))^2)/2)),
 
    p2 >= a/b - (w2 - c)/(b*v2) && a/b > p2 > w2 > 0 && 2/b > v2 > 0 &&

     b > 0}, {p2}]

Q3[w2_] =

Maximize[{(p2*d2 - (((w2)^2 - c^2)/(2*v2) + c*(d2 - (w2 - c)/v2))),

   p2 <= a/b - (w2 - c)/(b*v2) && 0 < c < w2 < (a - b*c)*v2 + c &&

    a/b > p2 > w2 > 0 && 2/b > v2 > 0 && b > 0}, {p2}]
By Q2, we can get optimal w2, Q3 will be the same. The optimal values are two piecewise functions, which are shown as follows:

I want to compare the results to get the global optimal w2 and its profit, for instance, if global w2=6, its profit is 8. Of course, I can deal with this problem by hand calculation. However, what I am going to do involves many maximizing problem, so it would be better to use a simple command to calculate it. Additionally, in order to ensure that the solution is meaningful, w2 is greater than c and smaller than 6. Obviously, as to p2, when 2<w2<6, it is meaningful, w2 in other interval is meaningless. 

another question is, if you change the assigment, for example, v2=1.5, mathematica doesn't work, the result is 

I tried several times and found that if your assigment is decimal number, it doesn't work, but it works for integers. Does it work only when the assigment is integer? What if I want to deal with decimal number? Thank you very much!
POSTED BY: Shaoyan Robert
A slight correction
m[x_] = PiecewiseExpand[Max[f[x], g[x]]]
POSTED BY: Frank Kampas
PiecewiseExpand does that. Notice the undelayed assignment for m (it is intentionally, so the right handside is evaluated only once, symbolically)
f[x_] := Piecewise[{{8, 1 < x < 2}, {2 x^2 - 1, 2 <= x < 10}}]
g[x_] := Piecewise[{{3, 1 < x < 3}, {x - 1, 3 <= x < 11}}]
m[x_]=PiecewiseExpand[Max[f[x], g[x]]]

Plot[{f[x], g[x], m[x]}, {x, 1, 11}, Frame -> True, AxesOrigin -> {1, 0}]


yehuda
Posted 11 years ago
Thank you. Maybe there doesn't exist this kind of command and we need to make programming ourselves?
POSTED BY: Shaoyan Robert
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract