Variable limit of the plot range

I have a line of code K1=1; Plot[ Table[K1 xt x - K1 x^2,{xt,0.5,2.5,0.2}],{x,0,1}]. It generates multiple plot for on the same figure but whenever x > xt, value becomes negative which I don't need in the plot. Is there a way to do something like this Plot[Table[K1 xt x - K1 x^2,{xt,0.5,2.5,0.2}],{x,0,xt}]. Whenever I run the 2nd command it returns a error saying Limiting value xt is not a machine sized real number(I think it basically need a constant to be there).

• It’ll be helpful to include definition for K1. – CA Trevillian Mar 7 at 6:41
• @CATrevillian K1=1 – A Q Mar 7 at 6:42
• Why not just change the PlotRange to remove the negative y-axis? – CA Trevillian Mar 7 at 6:46
• @CATrevillian Is there a better approach than adjusting the PlotRange? – A Q Mar 7 at 6:49
• Probably what kglr just posted :) but it ultimately depends on what you want to do with the plot/data/lines afterwards. – CA Trevillian Mar 7 at 6:51

You can use ConditionalExpression or Piecewise or RegionFunction as follows:

Plot[Evaluate @ Table[ConditionalExpression[K1 xt x - K1 x^2, x <= xt],
{xt, 0.5, 2.5, 0.2}], {x, 0, 1}]


Plot[Evaluate @ Table[Piecewise[{{K1 xt x - K1 x^2, x <= xt}}, Undefined],
{xt, 0.5, 2.5, 0.2}], {x, 0, 1}]

 same picture

Plot[Evaluate @ Table[K1 xt x - K1 x^2, {xt, 0.5, 2.5, 0.2}],
{x, 0, 1}, RegionFunction -> (#2 >= 0 &)]


• You know what I tried with piecewise but my x-axis was getting covered with the curve, I didn't know about the Undefined thing. Also, do you know the reason behind using Evaluate to get the coloured curves and without it, all the curves are of the same color. – A Q Mar 7 at 7:02
• @AQ, re the need for Evaluate please see this answer by Mr. Wizard – kglr Mar 7 at 7:06