One way could be
Manipulate[
Module[{y, x},
Plot[y = -3*x + 2, {x, from, to},
AspectRatio -> Automatic,
PlotRange -> {{from, to}, {from, to}}]
],
{{from, -10, "from"}, -10, -0.01, .01, Appearance -> "Labeled"},
{{to, 10, "to"}, 0, 10, .01, Appearance -> "Labeled"},
TrackedSymbols :> {from, to}
]
If you meant the from
and to
only for the x
part and not for the plotrange
, then you use this
Manipulate[
Module[{y, x},
Plot[y = -3*x + 2, {x, from, to},
AspectRatio -> Automatic,
PlotRange -> {{-20, 20}, {-20, 20}}]
],
{{from, -10, "from"}, -10, -0.01, .01, Appearance -> "Labeled"},
{{to, 10, "to"}, 0, 10, .01, Appearance -> "Labeled"},
TrackedSymbols :> {from, to}
]
You just need to make sure the from
is not larger than the to
, that is all, else Plot
complains.
And if you do not want to worry about from
being larger than to
, then you can add a small check in the code to check for this and adjust automatically, so Plot
stays happy.
Manipulate[
Module[{y, x},
(*prevent from from going above to to keep plot happy*)
If[from >= to, from = to - 0.01];
Plot[y = -3*x + 2, {x, from, to},
AspectRatio -> Automatic,
PlotRange -> {{-20, 20}, {-20, 20}}]
],
{{from, -10, "from"}, -10, 10, .01, Appearance -> "Labeled"},
{{to, 10, "to"}, -10, 10, .01, Appearance -> "Labeled"},
TrackedSymbols :> {from, to}
]
fr2
to{fr2, 10}
(i.e., set an initial value for that symbol) it will work. $\endgroup$Manipulate[ Plot[y = -3*x + 2, {x, {fr1, 10}, {fr2, 10}}, AspectRatio -> Automatic, PlotRange -> {{-20, 20}, {-20, 20}}], {fr1, -10, 10}, {fr2, -10, 10}
or thisManipulate[ Plot[y = -3*x + 2, {x, fr1, {fr2, 10}}, AspectRatio -> Automatic, PlotRange -> {{-20, 20}, {-20, 20}}], {fr1, -10, 10}, {fr2, -10, 10}
does not works. Can you please post corrected whole code? $\endgroup$Manipulate
unchanged (i.e., everything insidePlot
). You need to change{fr2, -10, 10}
to{{fr2, 10}, -10, 10}
in the last argument of Manipulate. $\endgroup$Manipulate[ Plot[y = -3*x + 2, {x, fr1, fr2}, AspectRatio -> Automatic, PlotRange -> {{-20, 20}, {-20, 20}}], {fr1, -10, 10}, {{fr2, 10}, -10, 10}]
$\endgroup$y = ...
inside ofPlot
. JustPlot[3*x + 2, {x, fr1, fr2}, ...]
will suffice. $\endgroup$