Message Boards Message Boards

[✓] Plot function that has piecewise function within?

GROUPS:

can anyone help me with plotting the graph as follows

e := 0.2;    bo := 1;    T := 2;    xo := 1;    x1 = -1;
u = Piecewise[{{1, -1 <= b <= 1 && (x^3) - 2*x + b > 0 || 
     b > 1 && x}}, 0]
PP = StreamPlot[{x - xo + (xo - x1)*u, -((x^3) - T*x + b)/e}, {b, -2, 
   2}, {x, -2, 2}]

This is the output

Attachments:
POSTED BY: Nur Syahirah
Answer
11 days ago

The last condition x in Piecewise is not a predicate: -1 <= b <= 1 && (x^3) - 2*x + b > 0 || b > 1 && x. This variation works:

e = 0.2; bo = 1; T = 2; xo = 1; x1 = -1;
u[b_, x_] := 
  Piecewise[{{1, -1 <= b <= 1 && (x^3) - 2*x + b > 0 || 
      b > 1 && x > 1}}, 0];
StreamPlot[
 PiecewiseExpand[{x - xo + (xo - x1)*u[b, x], -((x^3) - T*x + b)/
    e}], {b, -2, 2}, {x, -2, 2}]

I don't know why we need PiecewiseExpand.

POSTED BY: Gianluca Gorni
Answer
11 days ago

Group Abstract Group Abstract