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$

closed as off-topic by Bob Hanlon, march, MarcoB, m_goldberg, happy fish Feb 18 '17 at 4:30

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." – Bob Hanlon, march, MarcoB, m_goldberg, happy fish
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\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.