3
$\begingroup$

I have two piecewise functions that are defined on values of [0,200]. I would like to find out the maximum difference between the two values.

The usual Max[] function does not work because all values the two piecewise functions are integer values and are discontinuous.

I tried this

FindMaxValue[EDFh4 - CDFh4, x]

EDFh4 and CDFh4 are the two functions defined as:

CDFh4 = Piecewise[{#1, #2 <= x < #3} & @@ # & /@ CDFh3]
EDFh4 = Piecewise[{#1, #2 <= x < #3} & @@ # & /@ EDFh3]

The functions have vertical and horizontal components, never at the same time.

 CDFh3= {{1/30, 15, 30}, {1/15, 30, 40}, {1/10, 40, 50}, {2/15, 50, 60}, {1/5,
   60, 70}, {4/15, 70, 85}, {3/10, 85, 90}, {1/3, 90, 105}, {11/30, 
  105, 110}, {7/15, 110, 120}, {8/15, 120, 125}, {17/30, 125, 
  130}, {19/30, 130, 135}, {2/3, 135, 140}, {11/15, 140, 150}, {4/5, 
  150, 160}, {5/6, 160, 175}}


 EDFh3={{1/30, 10, 35}, {1/15, 35, 55}, {1/10, 55, 60}, {1/5, 60, 75}, {7/30,
   75, 80}, {4/15, 80, 110}, {1/3, 110, 120}, {13/30, 120, 125}, {8/
  15, 125, 130}, {19/30, 130, 135}, {7/10, 135, 140}, {11/15, 140, 
  145}, {4/5, 145, 150}, {5/6, 150, 165}, {9/10, 165, 180}, {14/15, 
  180, 185}, {29/30, 185, 190}}

enter image description here CDF Values: https://i.sstatic.net/teKvX.png EDF Values: https://i.sstatic.net/pXc3P.png

$\endgroup$
3
  • $\begingroup$ it would help if we had values of CDFh3 and EDFh3 to work with $\endgroup$
    – Pillsy
    Commented Mar 6, 2017 at 17:05
  • $\begingroup$ Hi @Pillsy I have updated the post to include links to the values of CDFh3 and EDFh3 $\endgroup$
    – Andre
    Commented Mar 6, 2017 at 17:18
  • 1
    $\begingroup$ can you just paste those in as a code block? thanks! $\endgroup$
    – Pillsy
    Commented Mar 6, 2017 at 17:41

2 Answers 2

2
$\begingroup$

Try

Maximize[EDFh4 - CDFh4, x]
(* {29/30, {x -> 185}} *)
$\endgroup$
1
$\begingroup$

You can do this straightforwardly:

CDFh4[x_] := Piecewise[{#1, #2 <= x < #3} & @@ # & /@ CDFh3];
EDFh4[x_] := Piecewise[{#1, #2 <= x < #3} & @@ # & /@ EDFh3];
Max[Abs[CDFh4[#] - EDFh4[#]] & /@ Range[1, 200]]
29/30
$\endgroup$
3
  • $\begingroup$ Or: Max@PiecewiseExpand[EDFh4 - CDFh4][[1, All, 1]]. $\endgroup$
    – march
    Commented Mar 6, 2017 at 18:28
  • $\begingroup$ @march Can you explain what the last statement is "[[1,All,1]]" $\endgroup$
    – Andre
    Commented Mar 6, 2017 at 19:54
  • $\begingroup$ f[[1, All, 1]] is the same as Part[[1, All, 1]]. Since everything in Mathematica is an expression, we can take Parts of those expressions just like we take Parts of Lists. Look up the documentation for Part. @Andre $\endgroup$
    – march
    Commented Mar 6, 2017 at 21:05

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.