1
$\begingroup$

I want to draw a graph of the function that I specified using Piecewise. Though I can draw a graph, I keep getting Min::nord/Max::nord errors saying invalid comparison with -xx + yy I attempted. The followings are my codes.

 ublb1[α_, H_, L_] := 1/2 (2 H - H^2 - 2 L + H L - H α + 2 L α - 
    H L α) - 
 1/2 Sqrt[-4 H^3 + H^4 + 4 H^2 L - 2 H^3 L + H^2 L^2 + 
   4 H^2 α + 2 H^3 α - 6 H^2 L α + 
   2 H^3 L α - 2 H^2 L^2 α - 3 H^2 α^2 + 
   2 H^2 L α^2 + H^2 L^2 α^2]

test[α_, H_, L_] := 
 Piecewise[{{ublb1[α, H, L], 
    0 < L < H < 1 && 
     2 L < H && (H - L)/(1 - H + H^2 - H L) <= α <= (
      H^2 - 2 H L + H^2 L + L^2 - H L^2)/(H^2 - H L + L^2 - H L^2) && 
     ublb1[α, H, L] ∈ Reals && 
     ublb1[α, H, L] <= (1 - α) (1 - H) (H - L)}, {Null, 
    True}}]

Manipulate[
 Plot[{test[α, H, L]}, {α, 0, 1}, AxesOrigin -> {0, 0}, 
  PlotRange -> {0, 1}, AspectRatio -> 1, Frame -> True], {H, 0, 
  1}, {L, 0, H/2}]

I don't understand why I keep getting the errors about the comparison between the complex number and the real number even though I already include the condition ublb1[α, H, L] ∈ Reals && ublb1[α, H, L] <= (1 - α) (1 - H) (H - L).

Thanks for your support in advance.

$\endgroup$
3
  • $\begingroup$ You probably need another condition in there. ublb1[0.3, 0.5, 0.2] is a complex number. It's coming from the Sqrt. For instance this is negative: With[{\[Alpha] = 0.3, H = 0.5, L = 0.2}, -4 H^3 + H^4 + 4 H^2 L - 2 H^3 L + H^2 L^2 + 4 H^2 \[Alpha] + 2 H^3 \[Alpha] - 6 H^2 L \[Alpha] + 2 H^3 L \[Alpha] - 2 H^2 L^2 \[Alpha] - 3 H^2 \[Alpha]^2 + 2 H^2 L \[Alpha]^2 + H^2 L^2 \[Alpha]^2 ] Also you should write ublb1[\[Alpha]_, H_, L_] := ... with underscores in the arguments of ublb1 as you're using SetDelayed like this. $\endgroup$
    – flinty
    Commented Jul 31, 2020 at 23:22
  • $\begingroup$ @flinty Oops. The underscore thing was a mistake. I know some parameter values will make the value inside the squared root negative so that the complex number will appear. My point is that I already give a condition that compare ublb1[alpha,H,L] with (1-alpha)(1-H)(H-L) only when ublb1[alpha,H,L] is real number, but I keep getting the errors regarding the comparison between complex number and the real number, which I don't understand. $\endgroup$
    – Chris
    Commented Jul 31, 2020 at 23:33
  • $\begingroup$ You need H^2 (H - L - [Alpha] + L [Alpha]) (-4 + H - L + 3 [Alpha] + L [Alpha]) > 0 (or the thing in the sqrt to be 0. (1-alpha)(1-H)(H-L) is not enough. $\endgroup$
    – flinty
    Commented Aug 1, 2020 at 0:08

2 Answers 2

1
$\begingroup$

As the OP points out, the functions are defined in a way that should prevent Min::nord/Max::nord errors. One fix is to add the option Exclusions -> None. When Plot[] examines the function to determine discontinuities, it analyzes piecewise functions. In this case, it seems to allow evaluation when it shouldn’t; or it should do so “secretly” under the cloak of Quiet[]. Probably worth reporting as a potential bug.

Manipulate[
 Plot[{test[α, H, L]}, {α, 0, 1},
  AxesOrigin -> {0, 0}, PlotRange -> {0, 1}, AspectRatio -> 1, 
  Frame -> True, Exclusions -> None],
 {H, 0, 1}, {L, 0, H/2}]
$\endgroup$
0
$\begingroup$

I resolved the issue by re-defining ublb1 as follows.

ublb1[α_, H_, L_] := 
  Piecewise[{{ 
     1/2 (2 H - H^2 - 2 L + H L - H α + 2 L α - 
         H L α) - 
      1/2 Sqrt[-4 H^3 + H^4 + 4 H^2 L - 2 H^3 L + H^2 L^2 + 
        4 H^2 α + 2 H^3 α - 6 H^2 L α + 
        2 H^3 L α - 2 H^2 L^2 α - 3 H^2 α^2 + 
        2 H^2 L α^2 + H^2 L^2 α^2], 
     Im[ 1/2 (2 H - H^2 - 2 L + H L - H α + 2 L α - 
           H L α) - 
        1/2 Sqrt[-4 H^3 + H^4 + 4 H^2 L - 2 H^3 L + H^2 L^2 + 
          4 H^2 α + 2 H^3 α - 6 H^2 L α + 
          2 H^3 L α - 2 H^2 L^2 α - 3 H^2 α^2 + 
          2 H^2 L α^2 + H^2 L^2 α^2]] == 0}, {Null, 
     True}}];
$\endgroup$

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.