I am interested in plooting x only from 0 to 1, and afterwards x^2, only from 1 to ... whatever

Plot[{x, x^2}, {x, 0, 2}]

Thus in a way, I want to combine the two functions into one.

Pleas show me how to do this.

Thank you :)


closed as off-topic by Karsten 7., bbgodfrey, Bob Hanlon, Michael E2, Yves Klett Apr 26 '15 at 18:07

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Karsten 7., bbgodfrey, Bob Hanlon, Michael E2, Yves Klett
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ Show[Plot[x^2, {x, 1, 3}], Plot[x, {x, 0, 1}], PlotRange -> All] $\endgroup$ – Karsten 7. Apr 26 '15 at 11:19
  • $\begingroup$ Piecewise or similar functions. $\endgroup$ – Karsten 7. Apr 26 '15 at 11:21
  • $\begingroup$ @Karsten7. Indeed, it's a bit hard to say if this question is about piecewise plotting, or multiple plots. $\endgroup$ – kirma Apr 26 '15 at 11:23

Combine Plots with Show, and remember to use PlotRange -> All:

 Plot[x, {x, 0, 1}, PlotStyle -> Blue],
 Plot[x^2, {x, 1, 2}, PlotStyle -> Red],
 PlotRange -> All]

enter image description here

Another option, as Karsten7. stated, is to use piecewise functions with non-numeric default value outside their domain:

 {Piecewise[{{x, x < 1}}, Null], 
  Piecewise[{{x^2, x >= 1}}, Null]},
 {x, 0, 2}]

enter image description here

Then again, if you are really interested of not having separate plots, you probably want a direct Piecewise expression like:

  {{x, x < 1},
   {x^2, x >= 1}}],
 {x, 0, 2}]

enter image description here


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