6
$\begingroup$

enter image description here

p[x_, left_, right_] := HeavisideTheta[x - left] HeavisideTheta[right - x]

Plot[{(1400 + 200 x) p[x, 0, 0.77], 
   3460 x p[x, 0, 0.36], 
   (1172 + 214 x) p[x, 0.36, 0.77]},
  {x, 0, 0.77}]

I have used above code to create the plot. I tried filling curve but I require it to be fill as marked in figure.

$\endgroup$
4
$\begingroup$

Here is one way to do it.

p[x_, left_, right_] :=  HeavisideTheta[x - left] HeavisideTheta[right - x]        

    Show[Plot[{(1400 + 200 x) p[x, 0, 0.77], 
       3460 x p[x, 0, 0.36], (1172 + 214 x) p[x, 0.36, 0.77]}, {x, 0, 
       0.36}, Filling -> {1 -> {2}}, PlotRange -> All], 
     Plot[{(1400 + 200 x) p[x, 0, 0.77], 
       3460 x p[x, 0, 0.36], (1172 + 214 x) p[x, 0.36, 0.77]}, {x, 0.36, 
       0.77}, Filling -> {1 -> {3}}, PlotRange -> All]]

enter image description here

$\endgroup$
4
$\begingroup$

With

p[x_, left_, right_] := UnitStep[x - left] UnitStep[right - x]

f1 = (1400 + 200 #) p[#, 0, 0.77] &;
f2 = 3460 # p[#, 0, 0.36] &;
f3 = (1172 + 214 #) p[#, 0.36, 0.77] &;

How about

Plot[{f1@x, If[f2@x >= f3@x, f2@x, f3@x]}, {x, 0, 0.77}, Filling -> {1 -> {2}}]

enter image description here

Or

Plot[{f1@x, If[f2@x >= f3@x, f2@x, f3@x], f2@x, f3@x}, {x, 0, 0.77}, Filling -> {1 -> {2}}, Exclusions -> All]

enter image description here

It's better to use UnitStep instead of HeavisideTheta, becasue with the former one gets a simple derivative (and the discountinuity can be easily located):

enter image description here

while one get a messy output for the latter:

enter image description here

FunctionDomain[the f functions, t] also don't work with HeavisideTheta, but yield True for the UnitStep case.

$\endgroup$
  • $\begingroup$ Does anyone have an idea how to get rid of the vertical line in the second plot? $\endgroup$ – corey979 Jun 9 '18 at 22:53
0
$\begingroup$

You can also wrap the second and third functions with ConditionalExpression[#, # > 0]&

p[x_, left_, right_] := HeavisideTheta[x - left] HeavisideTheta[right - x]

Plot[{(1400 + 200 x) p[x, 0, 0.77], 
  ConditionalExpression[#, # > 0] &[3460 x p[x, 0, 0.36]], 
  ConditionalExpression[#, # > 0] &[(1172 + 214 x) p[x, 0.36, 0.77]]}, 
 {x, 0, 0.77}, 
 PlotStyle -> {Red, Blue, Orange}, 
 Frame -> True, Axes -> False,  
 Filling -> {1 -> {{2}, LightBlue}, 1 -> {{3}, LightBlue}}]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.