1
plotb[{yLow_, yHigh_, x_, xLeft_, xRight_}] :=
  Plot[{If[yLow < yHigh, yLow], If[yLow < yHigh, yHigh]} , {x, xLeft, xRight}, 
  Filling -> {1 -> {2}}]
d[decesion_] := Table[plotb[decesion[[i]]], {i, 1, Length[decesion]}]
c = {{2/h + a + b, 3 h - a + 2 b, h, 0, 10}, {h + 2 a - b,4 h - a + b, h, 2 b, 6}};
Manipulate[Show[d[c]], {a, 0, 2}, {b, 0, 5}] 

I have many graphics to draw and the c list includes many sublists. I have three questions:

  1. Manipulate doesn' t work.
  2. I want to fill the regions when yLow < yHigh and just use Plot not use RegionPlot. It seems to be reduntant using two "if" expressions. I don't know whether it will be slow when c includes a lot of sublists due to the two reduntant "if" expressions.
  3. 2/h in c will be wrong when h is 0. Maybe it can work if I change 0 to 0.001. Is there any other way not to modify c. Because I have completed the list c, I don't want to modify it.

Thank you very much.

user73722
  • 33
  • 4
  • Also, see: https://mathematica.stackexchange.com/q/25087/1871 Since you can read Chinese, consider reading this tutorial: https://note.youdao.com/ynoteshare1/index.html?id=a9c14381c11b44ad47980c44c200d529&type=note To be more specific, define c as a function is the standard solution: Clear[c]; c[a_, b_] =… – xzczd Jul 12 '20 at 02:30
  • @xzczd Thank you for your suggestion. I search the solution in the website, but don't find them that you find. That resolve my question. Just doubt why do you know I can read Chinese. – user73722 Jul 12 '20 at 04:46
  • Because I see your post in Tieba. – xzczd Jul 12 '20 at 05:19

1 Answers1

2

I would not write your code the way you did. But for a quick fix for now, simply add LocalizeVariables -> False

plotb[{yLow_, yHigh_, x_, xLeft_, xRight_}] := 
 Plot[{If[yLow < yHigh, yLow], If[yLow < yHigh, yHigh]}, {x, xLeft, 
   xRight}, Filling -> {1 -> {2}}]
d[decesion_] := Table[plotb[decesion[[i]]], {i, 1, Length[decesion]}]
c = {{2/h + a + b, 3 h - a + 2 b, h, 0, 10}, {h + 2 a - b, 
    4 h - a + b, h, 2 b, 6}};
Manipulate[
 Show[d[c]],
 {{a, 0, "a"}, 0, 2, 1, Appearance -> "Labeled"},
 {{b, 0, "b"}, 0, 5, 1, Appearance -> "Labeled"},
 TrackedSymbols :> {a, b},
 LocalizeVariables -> False
 ]

enter image description here

If you want slider to move with smaller steps, replace

 {{a, 0, "a"}, 0, 2, 1, Appearance -> "Labeled"},
 {{b, 0, "b"}, 0, 5, 1, Appearance -> "Labeled"},

with

 {{a, 0, "a"}, 0, 2, 0.1, Appearance -> "Labeled"},
 {{b, 0, "b"}, 0, 5, 0.1, Appearance -> "Labeled"},
Nasser
  • 143,286
  • 11
  • 154
  • 359
  • Thank you. The LocalizeVariables -> False makes the variables as global. Other graphics will change due to the global variable because I draw many graphics in the note. It will run slow. – user73722 Jul 10 '20 at 17:36
  • @user73722 As I mentioned, I would not do it that way, but this is how your code is setup. It would be better to put all the functions used by Manipulate inside it. – Nasser Jul 10 '20 at 23:06