# If Which Piecewise-defined function [closed]

How would I write a function using If and/or Which command for following Piecewise-defined function then plot the function

f(x)=1, if x<=1
f(x)=x^3, if -1<x<=1
f(x)=-1, if x>1


This what I have so far

f[x_] := If[(x <= -1) && (x < 1 || x <= 1), x^3,
Which[x <= -1, -1, x > 1, 1]]


## closed as off-topic by Artes, rhermans, MarcoB, Bob Hanlon, dr.blochwaveDec 1 '15 at 22:32

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." – Artes, rhermans, MarcoB, Bob Hanlon, dr.blochwave
If this question can be reworded to fit the rules in the help center, please edit the question.

• Your function is confusing. You want $f(x) =1$ if $x\leq1$ and $f(x) = x^3$ if $x >1$? If so: f[x_ /; x <= 1] := 1; f[x_ /; x > 1] := x^3; of f[x_] := If[x <= 1, 1, x^3];. – march Dec 1 '15 at 17:09
• For mathematical functions, you should try Piecewise: reference.wolfram.com/language/ref/Piecewise.html. – Chip Hurst Dec 1 '15 at 17:13

f1[x_] = Piecewise[{{Sign[x], Abs[x] > 1}}, x^3];