Message Boards Message Boards

0
|
6169 Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Plot a function of x with different terms on R- and on R+?

Posted 7 years ago

Hello,

I want to Plot a function of x with different terms on R-, 0 and on R+ as one function rather than as a set of functions. How can I achieve that, there is no such example in the doc for Plot[]?

Thank you.

POSTED BY: LV VS
2 Replies

You can choose among different approaches. One is to combine different formulas for the negative and positive using Piecewise:

f[x_] = Piecewise[{{1 - x, x > 0}, {x - 1, x < 0}}];
Plot[f[x], {x, -2, 2}, Epilog -> {PointSize[Large], Point[{0, 1/2}]}]

Another way is to combine separate plots with Show:

Show[Plot[1 - x, {x, 0, 2}], Plot[x - 1, {x, -2, 0}], 
 Graphics[{PointSize[Large], Point[{0, 1/2}]}], PlotRange -> All]

An isolated point of the graph requires a separate treatment, as Plot is meant for curves only.

POSTED BY: Gianluca Gorni

Can you give a more concrete example of what you are looking for? I'm not sure I understand the question.

POSTED BY: Sean Clarke
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract