0
$\begingroup$

I'm having trouble plotting the piecewise function below. The only way I can replicate this function is using

Plot[Piecewise[{{x^2, x >= 0}, {0, x < 0}}], {x, -10, 10}]

When I define the piecewise function as:

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

and then plot unitstep[x], the graph turns out linear.

Am I missing something here?

enter image description here

$\endgroup$
  • $\begingroup$ Your second function is not proper Mathematica code. Can you post the commands exactly as you have them in your notebook? $\endgroup$ – Felix Feb 17 '17 at 23:23
1
$\begingroup$

You have apparently missed reading the documentation on defining functions.

If you define unitstep (not a good name) as follows

unitstep[x_] := Piecewise[{{x^2, x >= 0}, {0, x < 0}}]

then it plots as you would expect

plot

$\endgroup$

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