0
|
12061 Views
|
4 Replies
|
1 Total Likes
View groups...
Share
GROUPS:

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

Posted 10 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: 4 Replies
Sort By:
Posted 10 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
Posted 10 years ago
 A slight correctionm[x_] = PiecewiseExpand[Max[f[x], g[x]]]
Posted 10 years ago
 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 10 years ago
 Thank you. Maybe there doesn't exist this kind of command and we need to make programming ourselves?