Piecewise Function Error
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I want to plot such a figure
I used command Plot[Piecewise[1,x<0,x,x=0,1,x>0],x,-3,3]
.
But it shows wrong results.
plotting
add a comment |Â
up vote
1
down vote
favorite
I want to plot such a figure
I used command Plot[Piecewise[1,x<0,x,x=0,1,x>0],x,-3,3]
.
But it shows wrong results.
plotting
Lookup=
vs==
.
– Kuba♦
1 hour ago
@Kuba, Okay, but we can not not see the line to point (0,0)
– ABCDEMMM
1 hour ago
Correct but that was solved by kglr now.Plot
is not likely to exactly "hit"x==0
so that is why it looks like a straight line.
– Kuba♦
1 hour ago
@Kuba, also, Thanks a lot, Before only do it in PPTX.... .:)
– ABCDEMMM
1 hour ago
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I want to plot such a figure
I used command Plot[Piecewise[1,x<0,x,x=0,1,x>0],x,-3,3]
.
But it shows wrong results.
plotting
I want to plot such a figure
I used command Plot[Piecewise[1,x<0,x,x=0,1,x>0],x,-3,3]
.
But it shows wrong results.
plotting
plotting
edited 34 mins ago
asked 1 hour ago
ABCDEMMM
1367
1367
Lookup=
vs==
.
– Kuba♦
1 hour ago
@Kuba, Okay, but we can not not see the line to point (0,0)
– ABCDEMMM
1 hour ago
Correct but that was solved by kglr now.Plot
is not likely to exactly "hit"x==0
so that is why it looks like a straight line.
– Kuba♦
1 hour ago
@Kuba, also, Thanks a lot, Before only do it in PPTX.... .:)
– ABCDEMMM
1 hour ago
add a comment |Â
Lookup=
vs==
.
– Kuba♦
1 hour ago
@Kuba, Okay, but we can not not see the line to point (0,0)
– ABCDEMMM
1 hour ago
Correct but that was solved by kglr now.Plot
is not likely to exactly "hit"x==0
so that is why it looks like a straight line.
– Kuba♦
1 hour ago
@Kuba, also, Thanks a lot, Before only do it in PPTX.... .:)
– ABCDEMMM
1 hour ago
Lookup
=
vs ==
.– Kuba♦
1 hour ago
Lookup
=
vs ==
.– Kuba♦
1 hour ago
@Kuba, Okay, but we can not not see the line to point (0,0)
– ABCDEMMM
1 hour ago
@Kuba, Okay, but we can not not see the line to point (0,0)
– ABCDEMMM
1 hour ago
Correct but that was solved by kglr now.
Plot
is not likely to exactly "hit" x==0
so that is why it looks like a straight line.– Kuba♦
1 hour ago
Correct but that was solved by kglr now.
Plot
is not likely to exactly "hit" x==0
so that is why it looks like a straight line.– Kuba♦
1 hour ago
@Kuba, also, Thanks a lot, Before only do it in PPTX.... .:)
– ABCDEMMM
1 hour ago
@Kuba, also, Thanks a lot, Before only do it in PPTX.... .:)
– ABCDEMMM
1 hour ago
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
2
down vote
accepted
Update:
ParametricPlot[ x, 2, 0, 2 Rescale[x, -3, 3], x, -3, 3,
AxesLabel -> Style["x", 16], Style["y", 16],
AxesStyle -> Arrowheads[0.04],
Ticks -> None, ExclusionsStyle -> Automatic,
PlotStyle -> Directive[Thick, Black],
AspectRatio -> Automatic, PlotRangePadding -> .2, .5, 0., .5,
ImageSize -> Large ]
Original answer:
ParametricPlot[x, 0, x, 2, 0, 2 Rescale[x, -3, 3], x, -3, 3,
Axes -> False, PlotStyle -> Thick]
Alternatively, you can Plot
two Piecewise
functions with the option ExclusionsStyle
:
Plot[Piecewise[0, x < 0, 2, x > 0],
Piecewise[2, x < 0, 0, x > 0], x, -3, 3, Axes -> False,
ExclusionsStyle -> Automatic, PlotStyle -> Black, AspectRatio -> Automatic]
where is error in my code?
– ABCDEMMM
1 hour ago
why we can not see line to (0,0) using my method??
– ABCDEMMM
1 hour ago
@ABCDEMMM, (1) you should usex ==0
in the middle piece as Kuba commented (2) even then, it gives a single horizontal line at y==1 with a gap at x==0 .
– kglr
1 hour ago
how can we add -> x, ->y; symbols??
– ABCDEMMM
42 mins ago
@ABCDEMMM, you meanPlot[Piecewise[0, x < 0, 2, x > 0], Piecewise[2, x < 0, 0, x > 0], x, -3, 3, AxesLabel -> "x", "y", AxesStyle -> Arrowheads[0.04], Ticks -> None, ExclusionsStyle -> Automatic, PlotStyle -> Black, AspectRatio -> Automatic, PlotRangePadding -> .2, .5, 0., .5]
?
– kglr
35 mins ago
 |Â
show 1 more comment
up vote
1
down vote
Edit:
Graphics[Black, AbsoluteThickness@3, Line[0, 0, 0, 3],
Line[-3, 3, 3, 3], AbsoluteThickness[1.5],
Arrow[-5, 0, 5, 0], Arrow[0, 3, 0, 4],
Text[Style["x", 16, FontFamily -> "Times New Roman"], 4.5, 0.5]]
Here is alternatives:
Show[Plot[UnitStep[x], x, -3, 3,
PlotStyle -> Black, AbsoluteThickness@3, PlotRange -> 0, 1],
Plot[UnitStep[-x], x, -3, 3,
PlotStyle -> Black, AbsoluteThickness@3],
AxesStyle -> AbsoluteThickness@3, Ticks -> None, PlotRange -> 0, 1]
Or
Show[Plot[0, x, -3, 3, PlotStyle -> Black, AbsoluteThickness@3,
PlotRange -> 0, 1],
Plot[1, x, -3, 3, PlotStyle -> Black, AbsoluteThickness@3],
AxesStyle -> AbsoluteThickness@3, Ticks -> None, PlotRange -> 0, 1]
Or using Graphics
Graphics[Black, AbsoluteThickness@3, Line[0, 0, 0, 2],
Line[-3, 0, 3, 0], Line[-3, 2, 3, 2]]
you answer is also very helpful, thank you!
– ABCDEMMM
13 mins ago
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
Update:
ParametricPlot[ x, 2, 0, 2 Rescale[x, -3, 3], x, -3, 3,
AxesLabel -> Style["x", 16], Style["y", 16],
AxesStyle -> Arrowheads[0.04],
Ticks -> None, ExclusionsStyle -> Automatic,
PlotStyle -> Directive[Thick, Black],
AspectRatio -> Automatic, PlotRangePadding -> .2, .5, 0., .5,
ImageSize -> Large ]
Original answer:
ParametricPlot[x, 0, x, 2, 0, 2 Rescale[x, -3, 3], x, -3, 3,
Axes -> False, PlotStyle -> Thick]
Alternatively, you can Plot
two Piecewise
functions with the option ExclusionsStyle
:
Plot[Piecewise[0, x < 0, 2, x > 0],
Piecewise[2, x < 0, 0, x > 0], x, -3, 3, Axes -> False,
ExclusionsStyle -> Automatic, PlotStyle -> Black, AspectRatio -> Automatic]
where is error in my code?
– ABCDEMMM
1 hour ago
why we can not see line to (0,0) using my method??
– ABCDEMMM
1 hour ago
@ABCDEMMM, (1) you should usex ==0
in the middle piece as Kuba commented (2) even then, it gives a single horizontal line at y==1 with a gap at x==0 .
– kglr
1 hour ago
how can we add -> x, ->y; symbols??
– ABCDEMMM
42 mins ago
@ABCDEMMM, you meanPlot[Piecewise[0, x < 0, 2, x > 0], Piecewise[2, x < 0, 0, x > 0], x, -3, 3, AxesLabel -> "x", "y", AxesStyle -> Arrowheads[0.04], Ticks -> None, ExclusionsStyle -> Automatic, PlotStyle -> Black, AspectRatio -> Automatic, PlotRangePadding -> .2, .5, 0., .5]
?
– kglr
35 mins ago
 |Â
show 1 more comment
up vote
2
down vote
accepted
Update:
ParametricPlot[ x, 2, 0, 2 Rescale[x, -3, 3], x, -3, 3,
AxesLabel -> Style["x", 16], Style["y", 16],
AxesStyle -> Arrowheads[0.04],
Ticks -> None, ExclusionsStyle -> Automatic,
PlotStyle -> Directive[Thick, Black],
AspectRatio -> Automatic, PlotRangePadding -> .2, .5, 0., .5,
ImageSize -> Large ]
Original answer:
ParametricPlot[x, 0, x, 2, 0, 2 Rescale[x, -3, 3], x, -3, 3,
Axes -> False, PlotStyle -> Thick]
Alternatively, you can Plot
two Piecewise
functions with the option ExclusionsStyle
:
Plot[Piecewise[0, x < 0, 2, x > 0],
Piecewise[2, x < 0, 0, x > 0], x, -3, 3, Axes -> False,
ExclusionsStyle -> Automatic, PlotStyle -> Black, AspectRatio -> Automatic]
where is error in my code?
– ABCDEMMM
1 hour ago
why we can not see line to (0,0) using my method??
– ABCDEMMM
1 hour ago
@ABCDEMMM, (1) you should usex ==0
in the middle piece as Kuba commented (2) even then, it gives a single horizontal line at y==1 with a gap at x==0 .
– kglr
1 hour ago
how can we add -> x, ->y; symbols??
– ABCDEMMM
42 mins ago
@ABCDEMMM, you meanPlot[Piecewise[0, x < 0, 2, x > 0], Piecewise[2, x < 0, 0, x > 0], x, -3, 3, AxesLabel -> "x", "y", AxesStyle -> Arrowheads[0.04], Ticks -> None, ExclusionsStyle -> Automatic, PlotStyle -> Black, AspectRatio -> Automatic, PlotRangePadding -> .2, .5, 0., .5]
?
– kglr
35 mins ago
 |Â
show 1 more comment
up vote
2
down vote
accepted
up vote
2
down vote
accepted
Update:
ParametricPlot[ x, 2, 0, 2 Rescale[x, -3, 3], x, -3, 3,
AxesLabel -> Style["x", 16], Style["y", 16],
AxesStyle -> Arrowheads[0.04],
Ticks -> None, ExclusionsStyle -> Automatic,
PlotStyle -> Directive[Thick, Black],
AspectRatio -> Automatic, PlotRangePadding -> .2, .5, 0., .5,
ImageSize -> Large ]
Original answer:
ParametricPlot[x, 0, x, 2, 0, 2 Rescale[x, -3, 3], x, -3, 3,
Axes -> False, PlotStyle -> Thick]
Alternatively, you can Plot
two Piecewise
functions with the option ExclusionsStyle
:
Plot[Piecewise[0, x < 0, 2, x > 0],
Piecewise[2, x < 0, 0, x > 0], x, -3, 3, Axes -> False,
ExclusionsStyle -> Automatic, PlotStyle -> Black, AspectRatio -> Automatic]
Update:
ParametricPlot[ x, 2, 0, 2 Rescale[x, -3, 3], x, -3, 3,
AxesLabel -> Style["x", 16], Style["y", 16],
AxesStyle -> Arrowheads[0.04],
Ticks -> None, ExclusionsStyle -> Automatic,
PlotStyle -> Directive[Thick, Black],
AspectRatio -> Automatic, PlotRangePadding -> .2, .5, 0., .5,
ImageSize -> Large ]
Original answer:
ParametricPlot[x, 0, x, 2, 0, 2 Rescale[x, -3, 3], x, -3, 3,
Axes -> False, PlotStyle -> Thick]
Alternatively, you can Plot
two Piecewise
functions with the option ExclusionsStyle
:
Plot[Piecewise[0, x < 0, 2, x > 0],
Piecewise[2, x < 0, 0, x > 0], x, -3, 3, Axes -> False,
ExclusionsStyle -> Automatic, PlotStyle -> Black, AspectRatio -> Automatic]
edited 6 mins ago
answered 1 hour ago
kglr
167k8188392
167k8188392
where is error in my code?
– ABCDEMMM
1 hour ago
why we can not see line to (0,0) using my method??
– ABCDEMMM
1 hour ago
@ABCDEMMM, (1) you should usex ==0
in the middle piece as Kuba commented (2) even then, it gives a single horizontal line at y==1 with a gap at x==0 .
– kglr
1 hour ago
how can we add -> x, ->y; symbols??
– ABCDEMMM
42 mins ago
@ABCDEMMM, you meanPlot[Piecewise[0, x < 0, 2, x > 0], Piecewise[2, x < 0, 0, x > 0], x, -3, 3, AxesLabel -> "x", "y", AxesStyle -> Arrowheads[0.04], Ticks -> None, ExclusionsStyle -> Automatic, PlotStyle -> Black, AspectRatio -> Automatic, PlotRangePadding -> .2, .5, 0., .5]
?
– kglr
35 mins ago
 |Â
show 1 more comment
where is error in my code?
– ABCDEMMM
1 hour ago
why we can not see line to (0,0) using my method??
– ABCDEMMM
1 hour ago
@ABCDEMMM, (1) you should usex ==0
in the middle piece as Kuba commented (2) even then, it gives a single horizontal line at y==1 with a gap at x==0 .
– kglr
1 hour ago
how can we add -> x, ->y; symbols??
– ABCDEMMM
42 mins ago
@ABCDEMMM, you meanPlot[Piecewise[0, x < 0, 2, x > 0], Piecewise[2, x < 0, 0, x > 0], x, -3, 3, AxesLabel -> "x", "y", AxesStyle -> Arrowheads[0.04], Ticks -> None, ExclusionsStyle -> Automatic, PlotStyle -> Black, AspectRatio -> Automatic, PlotRangePadding -> .2, .5, 0., .5]
?
– kglr
35 mins ago
where is error in my code?
– ABCDEMMM
1 hour ago
where is error in my code?
– ABCDEMMM
1 hour ago
why we can not see line to (0,0) using my method??
– ABCDEMMM
1 hour ago
why we can not see line to (0,0) using my method??
– ABCDEMMM
1 hour ago
@ABCDEMMM, (1) you should use
x ==0
in the middle piece as Kuba commented (2) even then, it gives a single horizontal line at y==1 with a gap at x==0 .– kglr
1 hour ago
@ABCDEMMM, (1) you should use
x ==0
in the middle piece as Kuba commented (2) even then, it gives a single horizontal line at y==1 with a gap at x==0 .– kglr
1 hour ago
how can we add -> x, ->y; symbols??
– ABCDEMMM
42 mins ago
how can we add -> x, ->y; symbols??
– ABCDEMMM
42 mins ago
@ABCDEMMM, you mean
Plot[Piecewise[0, x < 0, 2, x > 0], Piecewise[2, x < 0, 0, x > 0], x, -3, 3, AxesLabel -> "x", "y", AxesStyle -> Arrowheads[0.04], Ticks -> None, ExclusionsStyle -> Automatic, PlotStyle -> Black, AspectRatio -> Automatic, PlotRangePadding -> .2, .5, 0., .5]
?– kglr
35 mins ago
@ABCDEMMM, you mean
Plot[Piecewise[0, x < 0, 2, x > 0], Piecewise[2, x < 0, 0, x > 0], x, -3, 3, AxesLabel -> "x", "y", AxesStyle -> Arrowheads[0.04], Ticks -> None, ExclusionsStyle -> Automatic, PlotStyle -> Black, AspectRatio -> Automatic, PlotRangePadding -> .2, .5, 0., .5]
?– kglr
35 mins ago
 |Â
show 1 more comment
up vote
1
down vote
Edit:
Graphics[Black, AbsoluteThickness@3, Line[0, 0, 0, 3],
Line[-3, 3, 3, 3], AbsoluteThickness[1.5],
Arrow[-5, 0, 5, 0], Arrow[0, 3, 0, 4],
Text[Style["x", 16, FontFamily -> "Times New Roman"], 4.5, 0.5]]
Here is alternatives:
Show[Plot[UnitStep[x], x, -3, 3,
PlotStyle -> Black, AbsoluteThickness@3, PlotRange -> 0, 1],
Plot[UnitStep[-x], x, -3, 3,
PlotStyle -> Black, AbsoluteThickness@3],
AxesStyle -> AbsoluteThickness@3, Ticks -> None, PlotRange -> 0, 1]
Or
Show[Plot[0, x, -3, 3, PlotStyle -> Black, AbsoluteThickness@3,
PlotRange -> 0, 1],
Plot[1, x, -3, 3, PlotStyle -> Black, AbsoluteThickness@3],
AxesStyle -> AbsoluteThickness@3, Ticks -> None, PlotRange -> 0, 1]
Or using Graphics
Graphics[Black, AbsoluteThickness@3, Line[0, 0, 0, 2],
Line[-3, 0, 3, 0], Line[-3, 2, 3, 2]]
you answer is also very helpful, thank you!
– ABCDEMMM
13 mins ago
add a comment |Â
up vote
1
down vote
Edit:
Graphics[Black, AbsoluteThickness@3, Line[0, 0, 0, 3],
Line[-3, 3, 3, 3], AbsoluteThickness[1.5],
Arrow[-5, 0, 5, 0], Arrow[0, 3, 0, 4],
Text[Style["x", 16, FontFamily -> "Times New Roman"], 4.5, 0.5]]
Here is alternatives:
Show[Plot[UnitStep[x], x, -3, 3,
PlotStyle -> Black, AbsoluteThickness@3, PlotRange -> 0, 1],
Plot[UnitStep[-x], x, -3, 3,
PlotStyle -> Black, AbsoluteThickness@3],
AxesStyle -> AbsoluteThickness@3, Ticks -> None, PlotRange -> 0, 1]
Or
Show[Plot[0, x, -3, 3, PlotStyle -> Black, AbsoluteThickness@3,
PlotRange -> 0, 1],
Plot[1, x, -3, 3, PlotStyle -> Black, AbsoluteThickness@3],
AxesStyle -> AbsoluteThickness@3, Ticks -> None, PlotRange -> 0, 1]
Or using Graphics
Graphics[Black, AbsoluteThickness@3, Line[0, 0, 0, 2],
Line[-3, 0, 3, 0], Line[-3, 2, 3, 2]]
you answer is also very helpful, thank you!
– ABCDEMMM
13 mins ago
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Edit:
Graphics[Black, AbsoluteThickness@3, Line[0, 0, 0, 3],
Line[-3, 3, 3, 3], AbsoluteThickness[1.5],
Arrow[-5, 0, 5, 0], Arrow[0, 3, 0, 4],
Text[Style["x", 16, FontFamily -> "Times New Roman"], 4.5, 0.5]]
Here is alternatives:
Show[Plot[UnitStep[x], x, -3, 3,
PlotStyle -> Black, AbsoluteThickness@3, PlotRange -> 0, 1],
Plot[UnitStep[-x], x, -3, 3,
PlotStyle -> Black, AbsoluteThickness@3],
AxesStyle -> AbsoluteThickness@3, Ticks -> None, PlotRange -> 0, 1]
Or
Show[Plot[0, x, -3, 3, PlotStyle -> Black, AbsoluteThickness@3,
PlotRange -> 0, 1],
Plot[1, x, -3, 3, PlotStyle -> Black, AbsoluteThickness@3],
AxesStyle -> AbsoluteThickness@3, Ticks -> None, PlotRange -> 0, 1]
Or using Graphics
Graphics[Black, AbsoluteThickness@3, Line[0, 0, 0, 2],
Line[-3, 0, 3, 0], Line[-3, 2, 3, 2]]
Edit:
Graphics[Black, AbsoluteThickness@3, Line[0, 0, 0, 3],
Line[-3, 3, 3, 3], AbsoluteThickness[1.5],
Arrow[-5, 0, 5, 0], Arrow[0, 3, 0, 4],
Text[Style["x", 16, FontFamily -> "Times New Roman"], 4.5, 0.5]]
Here is alternatives:
Show[Plot[UnitStep[x], x, -3, 3,
PlotStyle -> Black, AbsoluteThickness@3, PlotRange -> 0, 1],
Plot[UnitStep[-x], x, -3, 3,
PlotStyle -> Black, AbsoluteThickness@3],
AxesStyle -> AbsoluteThickness@3, Ticks -> None, PlotRange -> 0, 1]
Or
Show[Plot[0, x, -3, 3, PlotStyle -> Black, AbsoluteThickness@3,
PlotRange -> 0, 1],
Plot[1, x, -3, 3, PlotStyle -> Black, AbsoluteThickness@3],
AxesStyle -> AbsoluteThickness@3, Ticks -> None, PlotRange -> 0, 1]
Or using Graphics
Graphics[Black, AbsoluteThickness@3, Line[0, 0, 0, 2],
Line[-3, 0, 3, 0], Line[-3, 2, 3, 2]]
edited 12 mins ago
answered 49 mins ago
Okkes Dulgerci
3,3261616
3,3261616
you answer is also very helpful, thank you!
– ABCDEMMM
13 mins ago
add a comment |Â
you answer is also very helpful, thank you!
– ABCDEMMM
13 mins ago
you answer is also very helpful, thank you!
– ABCDEMMM
13 mins ago
you answer is also very helpful, thank you!
– ABCDEMMM
13 mins ago
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f184612%2fpiecewise-function-error%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Lookup
=
vs==
.– Kuba♦
1 hour ago
@Kuba, Okay, but we can not not see the line to point (0,0)
– ABCDEMMM
1 hour ago
Correct but that was solved by kglr now.
Plot
is not likely to exactly "hit"x==0
so that is why it looks like a straight line.– Kuba♦
1 hour ago
@Kuba, also, Thanks a lot, Before only do it in PPTX.... .:)
– ABCDEMMM
1 hour ago